59

Is it possible to install any version of Visual Studio in a Windows Container on a Windows Server?

The motivation is to use Windows Containers for building software in continuous integration systems, so that the build environment is standardized.

Jifeng Zhang
  • 4,807
  • 4
  • 27
  • 41

5 Answers5

27

Visual Studio seems to not be supported officially on Core Server, but I agree it would be really nice to be able to do this. Let's try:

FROM mcr.microsoft.com/windows/servercore:ltsc2019
SHELL ["powershell"]

RUN Invoke-WebRequest "https://aka.ms/vs/16/release/vs_community.exe" -OutFile "$env:TEMP\vs_community.exe" -UseBasicParsing
RUN & "$env:TEMP\vs_community.exe" --add Microsoft.VisualStudio.Workload.NetWeb --quiet --wait --norestart --noUpdateInstaller | Out-Default

RUN & 'C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/MSBuild/15.0/Bin/MSBuild.exe' /version

CMD ["powershell"]

(I'm pushing this image into lukaslansky/visualstudio-netwebworkload, use with caution.)

Output of the build is:

[...]
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

So this seems to work! You should play with those --add installator arguments to specify what components you need precisely for your build, they correspond to workloads and components you see in the GUI. See the documentation.

Lukáš Lánský
  • 3,937
  • 3
  • 29
  • 44
  • Would it be mandatory to use `windows server core`? If you're using docker for windows, wouldn't I be able just run it directly without using it as base? – Btc Sources Apr 09 '19 at 10:47
  • You need to pick a base to run it in the Docker world. I don't think VS can survive with Nano base. Do you know about any other option? – Lukáš Lánský Apr 14 '19 at 09:03
  • 1
    I wish I could give you more upvotes, because I've been searching for this solution for days. I finally have a Docker image that can build for .NET Framework 4.5, .NET Core 2.1 and .NET Core 3.1. All I had to do was take your command and enable some extra features. – Rob Spoor Dec 11 '19 at 16:48
3

Windows Containers do not currently include GUI apps. The limitation is on Microsoft, not on Docker.

For example try something simple like running Notepad (in Windows Server Core container). The process is launched but no GUI shows up.

Notepad launched, but no GUI shows up

xav
  • 744
  • 7
  • 9
3

Just for the record MS is not planning support VS inside containers, the best alternative that you have is MsBuild. Some months ago was possible but with the latest version from VS is not possible. Source: vsts-agents

Judavi
  • 117
  • 10
3

Your best bet at this point is to use Visual Studio Build Tools.

  • 1
    It lacks some workloads, but if you have all you need there it's the best choice. – Skyblade Oct 26 '18 at 15:34
  • Unfortunately the Build Tools do not install SSDT components anymore (or at least some [important components are missing](https://techcommunity.microsoft.com/t5/sql-server-integration-services/new-delivery-model-for-sql-server-data-tools-in-visual-studio/bc-p/963770/highlight/true#M578)). I am unable to build solutions containing database projects, so I really had to install VS. :/ – timmkrause Feb 12 '20 at 09:54
3

A way to install visual build chain in a windows container could be to use chocolatey package visualstudio2017buildtools.

Starting Dockerfile with something like :

FROM microsoft/windowsservercore
RUN powershell.exe -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SETX PATH "%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" 
RUN choco install -y  visualstudio2017buildtools --package-parameters "--add Microsoft.VisualStudio.Workload.VCTools --installPath C:\BuildTools" || IF "%ERRORLEVEL%"=="3010" EXIT 0      
RUN call "C:\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
mpromonet
  • 8,785
  • 40
  • 48
  • 80