Is it possible to install Visual Studio in a Windows Container
Asked Answered
I

6

68

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.

Incongruity answered 22/12, 2016 at 7:45 Comment(2)
Did you manage to find a satisfying answer to this question?Solvolysis
As an alternative, it's possible to run Visual Studio Code inside a container. Here's the official documentation on how: code.visualstudio.com/docs/remote/containers-tutorialFrancescafrancesco
M
31

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.

Molliemollify answered 22/9, 2017 at 12:21 Comment(3)
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?Clematis
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?Deibel
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.Mixture
L
6

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

Louden answered 11/7, 2018 at 2:3 Comment(2)
It lacks some workloads, but if you have all you need there it's the best choice.Doomsday
Unfortunately the Build Tools do not install SSDT components anymore (or at least some important components are missing). I am unable to build solutions containing database projects, so I really had to install VS. :/Zerlina
P
4

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"
Palsgrave answered 2/2, 2019 at 19:23 Comment(0)
C
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

Crocoite answered 12/2, 2018 at 17:6 Comment(0)
F
2

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

Firstly answered 1/12, 2017 at 3:1 Comment(1)
I don't think GUIs are relevant for CI scenarios the question is about.Deibel
S
0

I've recently spent a lot of time investigating this as our goal was to set up "dockerized" DevOps agents which were capable of running the VsBuild@1 pipeline task (among other things).

Generally, if you DON'T need VsBuild@1 (or some of the other tasks related to Visual Studio, like VsTest@2 or the like) then you're better of using https://hub.docker.com/_/microsoft-dotnet-framework-sdk/ as your base and call it a day; those images come with the Build Tools and VS Test agent already installed.

However it IS possible to install VS. Some notes:

  • I've had issues when installing VS on top of the images mentioned above. For some reason VS silently fails to copy some files when it detects some existing tools already being in place. As such, I recommend using the https://hub.docker.com/_/microsoft-dotnet-framework-runtime/ images as a base.
  • Installation must be "quiet" (since there's no GUI) and cannot request a restart.
  • From what I can tell VS would usually queue up some kind of pre-build process which isn't triggered when the system isn't restarted. This can be manually triggered, however, by running %windir%\Microsoft.NET\Framework64\v4.0.30319\ngen update. Do note that with a VS installation inside Docker this WILL fail in various ways, so you'll need to find ways around this.
  • Check the original DockerFile for the SDK images for some references; specifically interesting is the manual installation of .NET Framework targetting packs: https://github.com/microsoft/dotnet-framework-docker/blob/main/src/sdk/4.8.1/windowsservercore-ltsc2022/Dockerfile (Should this link ever stop working because the file is moved then it's worth taking a look at the DockerFiles in the https://github.com/microsoft/dotnet-framework-docker repo)
  • Not all VS components can be installed! While I haven't nailed it down to which components are troublesome, a full VS install inside Docker will likely exceed default Docker disk space limits and / or run endlessly (soft lock as some proces will wait forever for some other installation process to finish). As such it is important to carefully curate the list of VS component IDs you wish to install using --add arguments.
Stud answered 30/11, 2022 at 9:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.