Using Visual Studio Build tools in Docker on Windows Server 2016
The title of this article might seem oddly specific, but this turned out to be less straightforward than I thought it
would (or should) be. I run my Jenkins builds for Visual Studio on a VPS running Windows 2016 server. In the past I was
hit by a bug where the Visual Studio build tools installer would crash resulting in a corrupted .NET installation inside
of the container. More recently a Windows 2016 security update stirred things up even more.
Recently all my Windows docker jobs on Jenkins started failing. Cmake still worked, but anything related to Visual
Studio just crashed immediately. This turned out to be the result of a security update that I had received the night
My docker image is based on mcr.microsoft.com/dotnet/framework/runtime:4.8-windowsservercore-ltsc2016 and the
workaround described on the page seems straightforward. Since I’m manually installing Visual Studio build tools anyway,
I figured I didn’t need the dotnet framework base anymore, and I could base my docker image directly on
However if you do this, you will get hit by a much older bug where the Visual Studio build tools installer will stop
seemingly without error. However, after that, nothing related to .NET will work properly anymore in the container. Even
a simple echo call in Powershell will result in an error complaining about missing .NET 2.0 (which is strange in
The fix for this is to head over to github and clone the
microsoft/dotnet-framework-docker GIT repository. Then go to
the 4.8\runtime\windowsservercore-ltsc2016 subfolder and edit the Dockerfile there to use
mcr.microsoft.com/windows/servercore:10.0.14393.3504 instead of the default ltsc2016 version. Build this to a
local image with a name of your choosing. I called mine robindegen/windowsservercore_net48_runtime. Then rebuild the
Visual Studio build tools docker image based on this newly created image. The Visual Studio build tools installation
should now succeed and work properly.
For those interrested, here is the Dockerfile I use to install Visual Studio 2019 build tools. It also installs CMake,
NASM and everything needed to run a Jenkins slave inside of it. This configuration is based on several online examples.
I believe that the slave configuration can be simplified; but for the timebeing this works. The Jenkins JNLP portion is
based on an old version of the jenkinsci/docker-jnlp-slave repository.