├── .gitattributes ├── CONTRIBUTING.md ├── LICENSE.txt ├── README.md ├── SECURITY.md ├── managed-native-desktop ├── Dockerfile ├── Install.cmd └── README.md ├── native-desktop ├── Dockerfile ├── Install.cmd └── README.md └── web ├── Dockerfile ├── Install.cmd └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | We would love practical, unique, and inspiring samples to help developers tailor their own Dockerfiles to suit their needs. 3 | 4 | ## Rules 5 | 1. All contributions must install Visual Studio Build Tools. 6 | 2. All contributions must be text (dockerfiles, scripts, etc.). 7 | 3. All contributions must adopt the [MIT license](LICENSE.txt) in the root of this project with accompanied header (see [example](managed-native-desktop/Dockerfile)). 8 | 4. All contributions must be in a unique directory. 9 | 5. All contributions must have a README file explaining in generalized terms (i.e. no company secrets, but providing context on who you are or represents is optional and might be useful) what sort of workloads the Dockerfile supports (see [example](managed-native-desktop/README.md)). 10 | 6. All supporting files referenced within the Dockerfile must be text and included within the samples directory (see [example](managed-native-desktop/Install.cmd)). 11 | 7. All contributions must be tested and work if someone were to copy the files and run commands as described in your README. 12 | 8. All contributions must be easy to understand and must not be obfuscated. These are samples, and we want end users to be confident should they use these samples as a starting point for their pipeline. 13 | 9. Include a link to your README file in the root [README](README.md) sorted by its brief title. 14 | 15 | ## Template 16 | Please consider the [.NET Framework + native desktop](managed-native-desktop/README.md) sample a template and author yours similarly. 17 | 18 | ## Review 19 | The rules above will be enforced in pull request reviews and you may be asked to make changes. PRs that have not been fixed within 2 weeks may be abandoned. You can still make requested changes and re-submit at any time. 20 | 21 | ## Derivation 22 | Contributors are encouraged to derive new, tested samples that provide significant value. If you believe you have found a problem, please open a new issue and @tag the author of the sample. Since all these samples should be tested, the author's feedback will be vital during the review process. 23 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (C) Microsoft Corporation. All rights reserved. 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Samples 2 | You can install Visual Studio Build Tools [into a container](https://docs.microsoft.com/en-us/visualstudio/install/build-tools-container) to support a consistent, isolated build environment. This repository hosts a number of examples - and is accepting [contributions](CONTRIBUTING.md) for more, useful examples - you can use to build a container image using Build Tools tailored to your project types and build pipeline. Because these container images can be massive - larger than probably anyone needs - and the permutations of different Windows, Visual Studio, and .NET Framework versions would complicate which version you might need, you are encouraged to use these samples or build on them and publish, if desired, images to your own Docker registry on your LAN or WAN. 3 | 4 | Note that Visual Studio Build Tools is licensed as a [supplemental license](https://www.visualstudio.com/license-terms/mlt553512/) for Visual Studio. Images may only be pushed to repositories to provide pull access to users with a valid Visual Studio license. 5 | 6 | * [.NET Framework + native desktop](managed-native-desktop/README.md) 7 | * [Native desktop](native-desktop/README.md) 8 | 9 | ## Contributing 10 | To contribute your own sample Dockerfiles and optional support scripts, please see [CONTRIBUTING](CONTRIBUTING.md). 11 | 12 | ## License 13 | This project and all examples herein are licensed under the [MIT license](LICENSE.txt). Visual Studio Build Tools is licensed as [supplemental license](https://www.visualstudio.com/license-terms/mlt553512/) for Visual Studio. 14 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /managed-native-desktop/Dockerfile: -------------------------------------------------------------------------------- 1 | # escape=` 2 | 3 | # Copyright (C) Microsoft Corporation. All rights reserved. 4 | # Licensed under the MIT license. See LICENSE.txt in the project root for license information. 5 | 6 | ARG FROM_IMAGE=microsoft/dotnet-framework:3.5-sdk-windowsservercore-1709 7 | FROM ${FROM_IMAGE} 8 | 9 | # Reset the shell. 10 | SHELL ["cmd", "/S", "/C"] 11 | 12 | # Set up environment to collect install errors. 13 | COPY Install.cmd C:\TEMP\ 14 | ADD https://aka.ms/vscollect.exe C:\TEMP\collect.exe 15 | 16 | # Install Node.js LTS 17 | ADD https://nodejs.org/dist/v8.11.3/node-v8.11.3-x64.msi C:\TEMP\node-install.msi 18 | RUN start /wait msiexec.exe /i C:\TEMP\node-install.msi /l*vx "%TEMP%\MSI-node-install.log" /qn ADDLOCAL=ALL 19 | 20 | # Download channel for fixed install. 21 | ARG CHANNEL_URL=https://aka.ms/vs/17/release/channel 22 | ADD ${CHANNEL_URL} C:\TEMP\VisualStudio.chman 23 | 24 | # Download and install Build Tools for Visual Studio 2022. 25 | ADD https://aka.ms/vs/17/release/vs_buildtools.exe C:\TEMP\vs_buildtools.exe 26 | RUN C:\TEMP\Install.cmd C:\TEMP\vs_buildtools.exe --quiet --wait --norestart --nocache ` 27 | --channelUri C:\TEMP\VisualStudio.chman ` 28 | --installChannelUri C:\TEMP\VisualStudio.chman ` 29 | --add Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools ` 30 | --add Microsoft.Net.Component.3.5.DeveloperTools ` 31 | --add Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools ` 32 | --add Microsoft.Net.ComponentGroup.TargetingPacks.Common ` 33 | --add Microsoft.VisualStudio.Component.TestTools.BuildTools ` 34 | --add Microsoft.VisualStudio.Workload.VCTools ` 35 | --add Microsoft.VisualStudio.Component.VC.140 ` 36 | --add Microsoft.VisualStudio.Component.VC.ATL ` 37 | --add Microsoft.VisualStudio.Component.VC.CLI.Support ` 38 | --add Microsoft.VisualStudio.Component.Windows10SDK.16299.Desktop ` 39 | --add Microsoft.VisualStudio.ComponentGroup.NativeDesktop.WinXP ` 40 | --add Microsoft.VisualStudio.Workload.NodeBuildTools ` 41 | --add Microsoft.VisualStudio.Component.TypeScript.2.8 ` 42 | --installPath C:\BuildTools 43 | 44 | # Use developer command prompt and start PowerShell if no other command specified. 45 | ENTRYPOINT C:\BuildTools\Common7\Tools\VsDevCmd.bat && 46 | CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"] 47 | -------------------------------------------------------------------------------- /managed-native-desktop/Install.cmd: -------------------------------------------------------------------------------- 1 | @rem Copyright (C) Microsoft Corporation. All rights reserved. 2 | @rem Licensed under the MIT license. See LICENSE.txt in the project root for license information. 3 | 4 | @if not defined _echo echo off 5 | setlocal enabledelayedexpansion 6 | 7 | call %* 8 | if "%ERRORLEVEL%"=="3010" ( 9 | exit /b 0 10 | ) else ( 11 | if not "%ERRORLEVEL%"=="0" ( 12 | set ERR=%ERRORLEVEL% 13 | call C:\TEMP\collect.exe -zip:C:\vslogs.zip 14 | 15 | exit /b !ERR! 16 | ) 17 | ) 18 | -------------------------------------------------------------------------------- /managed-native-desktop/README.md: -------------------------------------------------------------------------------- 1 | # .NET Framework + native desktop 2 | The Visual Studio setup engine builds both managed and native projects. Some managed projects even target .NET Framework 3.5 to provide a better downlevel experience where 4.5 is not (yet) present. Because of that, we start from the microsoft/dotnet-framework:3.5-sdk-windowsservercore-1709 base image. We use RS3 because the same image can be used on Windows Server 2016 nodes that do not yet support RS4 containers. 3 | 4 | ## Building 5 | To build this image from this direectory, run: 6 | 7 | ```batch 8 | docker build -t buildtools2022:latest -m 2GB . 9 | ``` 10 | 11 | ## Running 12 | To map and build managed and native sources from a clean source repository, run: 13 | 14 | ```batch 15 | docker run -m 2G -v %CD%:C:\src buildtools2022:latest msbuild /m c:\src\Solution.sln 16 | ``` 17 | 18 | ## Issues 19 | 20 | * If the repository is not clean and the mapped directory is not on the same drive or the same path as the host directory, native project builds will fail with a front-end compiler error. 21 | -------------------------------------------------------------------------------- /native-desktop/Dockerfile: -------------------------------------------------------------------------------- 1 | # escape=` 2 | 3 | # Copyright (C) Microsoft Corporation. All rights reserved. 4 | # Licensed under the MIT license. See LICENSE.txt in the project root for license information. 5 | 6 | ARG FROM_IMAGE=microsoft/dotnet-framework:3.5-sdk-windowsservercore-1709 7 | FROM ${FROM_IMAGE} 8 | 9 | # Reset the shell. 10 | SHELL ["cmd", "/S", "/C"] 11 | 12 | # Set up environment to collect install errors. 13 | COPY Install.cmd C:\TEMP\ 14 | ADD https://aka.ms/vscollect.exe C:\TEMP\collect.exe 15 | 16 | # Install Node.js LTS 17 | ADD https://nodejs.org/dist/v8.11.3/node-v8.11.3-x64.msi C:\TEMP\node-install.msi 18 | RUN start /wait msiexec.exe /i C:\TEMP\node-install.msi /l*vx "%TEMP%\MSI-node-install.log" /qn ADDLOCAL=ALL 19 | 20 | # Download channel for fixed install. 21 | ARG CHANNEL_URL=https://aka.ms/vs/17/release/channel 22 | ADD ${CHANNEL_URL} C:\TEMP\VisualStudio.chman 23 | 24 | # Download and install Build Tools for Visual Studio 2022 for native desktop workload. 25 | ADD https://aka.ms/vs/17/release/vs_buildtools.exe C:\TEMP\vs_buildtools.exe 26 | RUN C:\TEMP\Install.cmd C:\TEMP\vs_buildtools.exe --quiet --wait --norestart --nocache ` 27 | --channelUri C:\TEMP\VisualStudio.chman ` 28 | --installChannelUri C:\TEMP\VisualStudio.chman ` 29 | --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended` 30 | --installPath C:\BuildTools 31 | 32 | # Use developer command prompt and start PowerShell if no other command specified. 33 | ENTRYPOINT C:\BuildTools\Common7\Tools\VsDevCmd.bat && 34 | CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"] 35 | -------------------------------------------------------------------------------- /native-desktop/Install.cmd: -------------------------------------------------------------------------------- 1 | @rem Copyright (C) Microsoft Corporation. All rights reserved. 2 | @rem Licensed under the MIT license. See LICENSE.txt in the project root for license information. 3 | 4 | @if not defined _echo echo off 5 | setlocal enabledelayedexpansion 6 | 7 | call %* 8 | if "%ERRORLEVEL%"=="3010" ( 9 | exit /b 0 10 | ) else ( 11 | if not "%ERRORLEVEL%"=="0" ( 12 | set ERR=%ERRORLEVEL% 13 | call C:\TEMP\collect.exe -zip:C:\vslogs.zip 14 | 15 | exit /b !ERR! 16 | ) 17 | ) 18 | -------------------------------------------------------------------------------- /native-desktop/README.md: -------------------------------------------------------------------------------- 1 | # Native desktop 2 | This sample produces an image that installs native C/C++ support only. It installs the core VC Tools workload with recommended components that include CMake and the Windows SDK. See our documentation for [additional workloads and components](http://aka.ms/vs/workloads) you can use. 3 | 4 | We start from the microsoft/dotnet-framework:3.5-sdk-windowsservercore-1709 base image for consistency with the managed-native-desktop sample. We use RS3 because the same image can be used on Windows Server 2016 nodes that do not yet support RS4 containers. 5 | 6 | ## Building 7 | To build this image from this directory, run: 8 | 9 | ```batch 10 | docker build -t buildtools2022native:latest -m 2GB . 11 | ``` 12 | 13 | ## Running 14 | To map and build native sources from a clean source repository, run: 15 | 16 | ```batch 17 | docker run -m 2G -v %CD%:C:\src buildtools2022native:latest --name Solution msbuild /m c:\src\Solution.sln 18 | ``` 19 | 20 | You can optionally pass specific configurations to build as well. 21 | 22 | ```batch 23 | docker run -m 2G -v %CD%:C:\src buildtools2022native:latest --name Solution msbuild /m c:\src\Solution.sln /p:Configuration=Debug /p:Platform=x64 24 | ``` 25 | 26 | To build again run the container created in the previous step, e.g. 27 | ```batch 28 | docker start -a Solution 29 | ``` 30 | 31 | You can omit the -a that attaches the container to view the output if desired. 32 | 33 | ## Issues 34 | 35 | * If the repository is not clean and the mapped directory is not on the same drive or the same path as the host directory, native project builds will fail with a front-end compiler error. 36 | * The compile flag /CI causes a compiler error when used in a container. In your project properties under C/C++ change Debug Information Format to C7 compatible when building in a container. 37 | -------------------------------------------------------------------------------- /web/Dockerfile: -------------------------------------------------------------------------------- 1 | # escape=` 2 | 3 | # Copyright (C) Microsoft Corporation. All rights reserved. 4 | # Licensed under the MIT license. See LICENSE.txt in the project root for license information. 5 | 6 | ARG FROM_IMAGE=microsoft/dotnet-framework:3.5-sdk-windowsservercore-1709 7 | FROM ${FROM_IMAGE} 8 | 9 | # Reset the shell. 10 | SHELL ["cmd", "/S", "/C"] 11 | 12 | # Set up environment to collect install errors. 13 | COPY Install.cmd C:\TEMP\ 14 | ADD https://aka.ms/vscollect.exe C:\TEMP\collect.exe 15 | 16 | # Install Node.js LTS 17 | ADD https://nodejs.org/dist/v8.11.3/node-v8.11.3-x64.msi C:\TEMP\node-install.msi 18 | RUN start /wait msiexec.exe /i C:\TEMP\node-install.msi /l*vx "%TEMP%\MSI-node-install.log" /qn ADDLOCAL=ALL 19 | 20 | # Download channel for fixed install. 21 | ARG CHANNEL_URL=https://aka.ms/vs/17/release/channel 22 | ADD ${CHANNEL_URL} C:\TEMP\VisualStudio.chman 23 | 24 | # Download and install Build Tools for Visual Studio 2022. 25 | ADD https://aka.ms/vs/17/release/vs_buildtools.exe C:\TEMP\vs_buildtools.exe 26 | RUN C:\TEMP\Install.cmd C:\TEMP\vs_buildtools.exe --quiet --wait --norestart --nocache ` 27 | --channelUri C:\TEMP\VisualStudio.chman ` 28 | --installChannelUri C:\TEMP\VisualStudio.chman ` 29 | --add Microsoft.VisualStudio.Workload.NetCoreBuildTools` 30 | --add Microsoft.VisualStudio.Workload.WebBuildTools` 31 | --add Microsoft.VisualStudio.Workload.NodeBuildTools ` 32 | --add Microsoft.VisualStudio.Component.TypeScript.2.8 ` 33 | --includeOptional --includeRecommended ` 34 | --installPath C:\BuildTools 35 | 36 | ENV MSBuildBinPath C:\BuildTools\MSBuild\15.0\Bin\ 37 | ENV MSBuildExtensionsPath C:\BuildTools\ 38 | ENV MSBuildExtensionsPath32 C:\BuildTools\ 39 | 40 | # Use developer command prompt and start PowerShell if no other command specified. 41 | ENTRYPOINT C:\BuildTools\Common7\Tools\VsDevCmd.bat && 42 | CMD ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"] 43 | -------------------------------------------------------------------------------- /web/Install.cmd: -------------------------------------------------------------------------------- 1 | @rem Copyright (C) Microsoft Corporation. All rights reserved. 2 | @rem Licensed under the MIT license. See LICENSE.txt in the project root for license information. 3 | 4 | @if not defined _echo echo off 5 | setlocal enabledelayedexpansion 6 | 7 | call %* 8 | if "%ERRORLEVEL%"=="3010" ( 9 | exit /b 0 10 | ) else ( 11 | if not "%ERRORLEVEL%"=="0" ( 12 | set ERR=%ERRORLEVEL% 13 | call C:\TEMP\collect.exe -zip:C:\vslogs.zip 14 | 15 | exit /b !ERR! 16 | ) 17 | ) 18 | -------------------------------------------------------------------------------- /web/README.md: -------------------------------------------------------------------------------- 1 | # Web apps 2 | This sample produces an image that installs required framework and workloads for web app authoring. 3 | 4 | We start from the microsoft/dotnet-framework:3.5-sdk-windowsservercore-1709 base image for consistency with the managed-native-desktop sample. We use RS3 because the same image can be used on Windows Server 2016 nodes that do not yet support RS4 containers. 5 | 6 | On top of that we add the workloads for building .NET and .NET Core apps. Also add environment variables that point to the `msbuild` and extensions paths. These are used in `.csproj` files to `find` the location of tools. 7 | 8 | ## Building 9 | To build this image from this directory, run: 10 | 11 | ```batch 12 | docker build -t buildtools2022web:latest -m 2GB . 13 | ``` 14 | ## Running with CAKE 15 | Assuming CAKE is used then a `build.ps1` script should be available. It can be run using the following command from a clean source repository: 16 | 17 | ```batch 18 | docker run -m 2G ^ 19 | -v %CD%:c:\src ^ 20 | -w c:\src ^ 21 | buildtools2022web:latest ^ 22 | powershell .\build.ps1 -Target="Default" -Transform="Debug" -Configuration="Debug 23 | ``` 24 | - runs `buildtools2022web:latest` and passes in the current working directory `%CD%` and designates it `c:\src` 'inside' the container 25 | - designates the working directory to `c:\src` 26 | - starts the `build.ps1` script (in this instance with a debug config) 27 | 28 | ## Running 29 | To map and build web sources from a clean source repository, run: 30 | 31 | ```batch 32 | docker run -m 2G -v %CD%:C:\src buildtools2022web:latest --name Solution msbuild /m c:\src\Solution.sln 33 | ``` 34 | 35 | You can optionally pass specific configurations to build as well. 36 | 37 | ```batch 38 | docker run -m 2G -v %CD%:C:\src buildtools2022web:latest --name Solution msbuild /m c:\src\Solution.sln /p:Configuration=Debug /p:Platform=x64 39 | ``` 40 | 41 | To build again run the container created in the previous step, e.g. 42 | ```batch 43 | docker start -a Solution 44 | ``` 45 | 46 | You can omit the -a that attaches the container to view the output if desired. 47 | 48 | ## Issues 49 | 50 | * If the repository is not clean and the mapped directory is not on the same drive or the same path as the host directory, web project builds will fail with a front-end compiler error. 51 | * The compile flag /CI causes a compiler error when used in a container. In your project properties under C/C++ change Debug Information Format to C7 compatible when building in a container. 52 | --------------------------------------------------------------------------------