Visual Studio Build Tools Container
 
 
Go to file
JoYo 5ab3d021bc simplified vs_config 2023-03-27 14:19:35 -04:00
.gitignore init 2021-02-18 13:39:35 -05:00
Dockerfile simplified vs_config 2023-03-27 14:19:35 -04:00
README.mdown simplified vs_config 2023-03-27 14:19:35 -04:00
docker-compose.yaml tag ltsc2022 2023-03-27 11:38:31 -04:00
rust.Dockerfile vscode installs clippy already 2023-03-27 13:17:38 -04:00
win_build_tools_install.ps1 updated to current vs17 and ucrt 2023-03-27 13:16:49 -04:00
winxp.Dockerfile simplified vs_config 2023-03-27 14:19:35 -04:00
winxp_build_tools_install.ps1 init 2021-02-18 13:39:35 -05:00

README.mdown

Visual Studio Build Tools Container

This project builds a minimal (ish) Docker container for the Visual Studio build tools (MSVC). A second image is constructed for Windows XP Visual Studio build tools (v141_xp). Powershell scripts are included to try and recreate these build environments directly on a Windows 10 workstation.

Requirements

A Windows 10.0.19041.804+ workstation or VM with minimum 8 GB of memory is required. The more concurrent containers you have running, the more memory and CPU cores are required.

Each container requires one core and approximately 4 GB of memory.

  1. Download and install Docker for Windows.

    • Select "Switch to Windows Containers" when prompted.

Build Image

Prior to running a container the Docker image will need to be built. This step is automated but time consuming. It only needs to be built once.

  1. Open powershell and navigate to this project.

  2. Run docker compose with the configuration provided by this project in docker-compose.yaml

    docker-compose build
    

This will install both the Windows v142 and Windows XP v141_xp build chains into their respective containers.

Reference these containers later with the names:

  • win_build

  • rust_build

  • winxp_build

Run Containers

It is recommend that a docker compose file is used to run these containers as paths on Windows can be a bit tricky. Make sure to use forward slashes in paths used within docker compose files.

Below is an example docker-compose.yaml file used to build a project configured with cmake.

version: '3'

services:
  win_build:
    image: win_build
    volumes:
      - .:C:/source/
  • volumes: are mounted within the Docker container.

    • C:/source/ is assumed to be the project being build with MSVC.

To build a Windows XP project use the image: winxp_build container image.

Build Your Windows Project

The above docker-compose.yaml file should be stored within your project and will reference the built Docker images by name, not by path. Once this file is created within your project run the following command to begin the build process.

docker-compose run win_build

This will drop you into the visual studio developer shell or console for winxp.

To modify the developer shell environments replace entrypoint: in your docker-compose.yaml with the desired environment variables or scripted build commands.

version: '3'

services:
  win_build:
    image: win_build
    volumes:
      - .:C:/source/
    entrypoint: powershell -Command Import-Module C:\\msvc\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll; Enter-VsDevShell -VsInstallPath C:\\msvc\\ -DevCmdArguments -arch=amd64

Optional Workstation Scripts

We have done our best to provide powershell scripts that should reproduce these build environments on a Windows 10 workstation. They can be ran but should be evaluated as there is no error checking.

Troubleshooting

error C2471: cannot update program database

MSBuild has trouble writing files to a mounted directory which occurs even if the out path is set in the project. It is recommended that you include a script in your project that copies the C:\source directory into the container prior to running the build commands.

Copy-Item C:\source\ -Destination C:\build\ -Recurse -Force
MSBuild C:\build\project.sln
Copy-Item C:\build\bin -Destination C:\source\ -Recurse -Force
Remove-Item -Recurse C:\build\

docker-compose build not implimented

https://docs.docker.com/compose/cli-command/#compose-v2-and-the-new-docker-compose-command

Docker Desktop includes an experimental version of docker-compose which may result in this error. Use the following command to disable.

docker-compose disable-v2

service immediately exits on docker-compose up

Reminder to run the container instead:

docker-compose run win_build