From 8320dfbb2a3c319bea2167a98d99fe82c849a9a9 Mon Sep 17 00:00:00 2001 From: JoYo <> Date: Thu, 18 Feb 2021 13:39:35 -0500 Subject: [PATCH] init --- .gitignore | 3 ++ Dockerfile | 16 +++++++ README.mdown | 82 +++++++++++++++++++++++++++++++++++ docker-compose.yaml | 19 ++++++++ vs15.config | 7 +++ vs16.config | 9 ++++ win_build_tools_install.ps1 | 21 +++++++++ winxp.Dockerfile | 16 +++++++ winxp_build_tools_install.ps1 | 21 +++++++++ 9 files changed, 194 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 README.mdown create mode 100644 docker-compose.yaml create mode 100644 vs15.config create mode 100644 vs16.config create mode 100644 win_build_tools_install.ps1 create mode 100644 winxp.Dockerfile create mode 100644 winxp_build_tools_install.ps1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bac3aba --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vscode/ +*.exe +*.chman diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..a5e1535 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# escape=` +FROM mcr.microsoft.com/windows/servercore:2004 + +ADD https://aka.ms/vs/16/release/channel C:\docker\visualstudio.release.chman +ADD https://aka.ms/vs/16/release/vs_buildtools.exe C:\docker\vs_buildtools.exe +COPY vs16.config C:\docker\.vsconfig + +RUN C:\docker\vs_buildtools.exe --quiet --wait --norestart --nocache ` + --channelUri C:\docker\visualstudio.release.chman ` + --installChannelUri C:\docker\visualstudio.release.chman ` + --config "C:\docker\.vsconfig" ` + --installPath C:\msvc + +VOLUME C:\source\ +WORKDIR C:\source\ +CMD ["powershell", "-NoExit", "-Command", "Import-Module C:\\msvc\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll;", "Enter-VsDevShell -Verbose -VsInstallPath C:\\msvc\\ -DevCmdArguments -arch=amd64"] diff --git a/README.mdown b/README.mdown new file mode 100644 index 0000000..102f520 --- /dev/null +++ b/README.mdown @@ -0,0 +1,82 @@ +# 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 workstation or VM with minimum 8 GB of memory is required. +The more concurrent containers you have running, the more memory and CPU cores is required. + +**Each container requires one core and approximately 4 GB of memory.** + +0. Download and install [Docker for Windows](https://download.docker.com/win/stable/Docker%20for%20Windows%20Installer.exe). + + - 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. + +0. Open powershell and navigate to this project. + +0. Run docker compose with the configuration provided by this project in `docker-compose.yaml` + + ```bash + 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 + +- 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. + +```yaml +version: '3' + +services: + win64_build_release: + image: win_build + volumes: + - .:C:/source/ + command: msbuild . +``` + +- `volumes:` are mounted within the Docker container. + + - `C:/source/` is assumed to be the project being build with MSVC. + +- `command:` passes arguments to `Microsoft.VisualStudio.DevShell` unless entrypoint is otherwise defined. + +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. + +```bash +docker-compose up +``` + +# 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. + +- [win_build_tools_install.ps1](win_build_tools_install.ps1) + +- [winxp_build_tools_install.ps1](winxp_build_tools_install.ps1) diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..6a562cc --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,19 @@ +version: '3' + +services: + win_build: + image: win_build + build: + context: . + volumes: + - .:C:/source/ + command: msbuild . + + winxp_build: + image: winxp_build + build: + context: . + dockerfile: winxp.Dockerfile + volumes: + - .:C:/source/ + command: msbuild . diff --git a/vs15.config b/vs15.config new file mode 100644 index 0000000..592a02b --- /dev/null +++ b/vs15.config @@ -0,0 +1,7 @@ +{ + "version": "1.0", + "components": [ + "Microsoft.VisualStudio.Workload.VCTools", + "Microsoft.VisualStudio.ComponentGroup.NativeDesktop.WinXP" + ] +} diff --git a/vs16.config b/vs16.config new file mode 100644 index 0000000..fffc3c2 --- /dev/null +++ b/vs16.config @@ -0,0 +1,9 @@ +{ + "version": "1.0", + "components": [ + "Microsoft.VisualStudio.Workload.VCTools", + "Microsoft.VisualStudio.Component.NuGet", + "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", + "Microsoft.VisualStudio.Component.Windows10SDK.18362" + ] +} diff --git a/win_build_tools_install.ps1 b/win_build_tools_install.ps1 new file mode 100644 index 0000000..bdc2a8c --- /dev/null +++ b/win_build_tools_install.ps1 @@ -0,0 +1,21 @@ +param([parameter()][string] $msvc="C:\msvc") + +new-item -path $msvc -type directory -force +new-item -path "temp" -type directory -force + +invoke-webrequest https://aka.ms/vs/16/release/channel -outfile temp\visualstudio.release.chman +invoke-webrequest https://aka.ms/vs/16/release/vs_buildtools.exe -outfile temp\vs_buildtools.exe + +$arguments = @( + "--quiet", "--wait", "--norestart", "--nocache", + "--channeluri", ($pwd.path + "\temp\visualstudio.release.chman"), + "--installchanneluri", ($pwd.path + "\temp\visualstudio.release.chman"), + "--config", ($pwd.path + "\vs16.config"), + "--installpath", "$msvc" +) + +$proc = Start-Process -FilePath "temp\vs_buildtools.exe" -ArgumentList $arguments +$proc.WaitForExit() +Remove-Item "temp" -Recurse + +[Environment]::SetEnvironmentVariable("Path", $env:Path + ";$msvc", "Machine") diff --git a/winxp.Dockerfile b/winxp.Dockerfile new file mode 100644 index 0000000..e1cd015 --- /dev/null +++ b/winxp.Dockerfile @@ -0,0 +1,16 @@ +# escape=` +FROM mcr.microsoft.com/windows/servercore:2004 + +ADD https://aka.ms/vs/15/release/channel C:\docker\visualstudio.release.chman +ADD https://aka.ms/vs/15/release/vs_buildtools.exe C:\docker\vs_buildtools.exe +COPY vs15.config C:\docker\.vsconfig + +RUN C:\docker\vs_buildtools.exe --quiet --wait --norestart --nocache ` + --channelUri C:\docker\visualstudio.release.chman ` + --installChannelUri C:\docker\visualstudio.release.chman ` + --config "C:\docker\.vsconfig" ` + --installPath C:\msvc + +VOLUME C:\source\ +WORKDIR C:\source\ +CMD ["powershell", "-NoExit", "-Command", "Import-Module C:\\msvc\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll;", "Enter-VsDevShell -Verbose -VsInstallPath C:\\msvc\\ -DevCmdArguments -arch=amd64"] diff --git a/winxp_build_tools_install.ps1 b/winxp_build_tools_install.ps1 new file mode 100644 index 0000000..a2ec025 --- /dev/null +++ b/winxp_build_tools_install.ps1 @@ -0,0 +1,21 @@ +param([parameter()][string] $msvc="C:\msvc") + +new-item -path $msvc -type directory -force +new-item -path "temp" -type directory -force + +invoke-webrequest https://aka.ms/vs/15/release/channel -outfile temp\visualstudio.release.chman +invoke-webrequest https://aka.ms/vs/15/release/vs_buildtools.exe -outfile temp\vs_buildtools.exe + +$arguments = @( + "--quiet", "--wait", "--norestart", "--nocache", + "--channeluri", ($pwd.path + "\temp\visualstudio.release.chman"), + "--installchanneluri", ($pwd.path + "\temp\visualstudio.release.chman"), + "--config", ($pwd.path + "\vs15.config"), + "--installpath", "$msvc" +) + +$proc = Start-Process -FilePath "temp\vs_buildtools.exe" -ArgumentList $arguments +$proc.WaitForExit() +Remove-Item "temp" -Recurse + +[Environment]::SetEnvironmentVariable("Path", $env:Path + ";$msvc", "Machine")