Install Build Tools into a Container

In this article

You can install Visual Studio Build Tools into a Windows container to support continuous integration and continuous delivery (CI/CD) workflows. This article guides you through what Docker configuration changes are required as well as what workloads and components you can install in a container.

Containers are a great way to package a consistent build system you can use not only in a CI/CD server environment but for development environments as well. You can, for example, mount your source code into a container to be built by a customized environment while you continue to use Visual Studio or other tools to write your code. If your CI/CD workflow uses the same container image, you can rest assured that your code builds consistently. You can use containers for runtime consistency as well, which is common for micro-services using multiple containers with an orchestration system, but is beyond the scope of this article.

If Visual Studio Build Tools does not have what you require to build your source code, these same steps can be used for other Visual Studio products. Do note, however, that Windows containers do not support an interactive user interface so all commands must be automated.

Overview

Using Docker you create an image from which you can create containers that build your source code. The example Dockerfile installs the latest Visual Studio Build Tools 2017 and some other helpful programs often used for building source code. You can further modify your own Dockerfile to include other tools and scripts to run tests, publish build output, and more.

If you have already installed Docker for Windows, you can skip to step 3.

Step 1. Enable Hyper-V

Hyper-V is not enabled by default. It must be enabled to start Docker for Windows, since currently only Hyper-V isolation is supported for Windows 10.

Step 3. Switch to Windows Containers

You can only install Build Tools 2017 on Windows, which requires you switch to Windows containers. Windows containers on Windows 10 support only Hyper-V isolation, while Windows containers on Windows Server 2016 support both Hyper-V and process isolation.

Step 4. Expand maximum container disk size

Visual Studio Build Tools - and to a greater extent, Visual Studio - require lots of disk space for all the tools that get installed. Even though our example Dockerfile disables the package cache, the disk size of container images must be increased to accommodate the space required. Currently on Windows, you can only increase disk size by changing the Docker configuration.

This command builds the Dockerfile in the current directory using 2GB of memory. The default 1GB is not sufficient when some workloads are installed; however, you may be able to build with only 1GB of memory depending on your build requirements.

The final image is tagged "buildtools2017:latest" so you can easily run it in a container as "buildtools2017" since the "latest" tag is the default if no tag is specified. If you want to use a specific version of Visual Studio Build Tools 2017 in a more advanced scenario, you might instead tag the container with a specific Visual Studio build number as well as "latest" so containers can use a specific version consistently.

Step 6. Using the built image

Now that you have created an image, you can run it in a container to do both interactive and automated builds. The example uses the Developer Command Prompt, so your PATH and other environment variables are already configured.

Open a command prompt.

Run the container to start a PowerShell environment with all developer environment variables set: