anden-akkio
anden-akkio

Reputation: 1247

Visual Studio 2015 Build Tools / CPP Runtime v140 Dockerfile isn't working correctly

I have been trying to set up a Dockerfile to run a project developed in Visual Studio 2015 on CPP Runtime v140 for a week or two now (specifically, this one, where I essentially just docker cp it in and then msbuild the solution file) and I keep running into issues.

Here is my current Dockerfile:

# escape=`

FROM mcr.microsoft.com/windows/servercore:ltsc2019

# Restore the default Windows shell for correct batch processing.
SHELL ["cmd", "/S", "/C"]

# Install Visual Studio 2015 Build Tools
ADD https://download.microsoft.com/download/E/E/D/EEDF18A8-4AED-4CE0-BEBE-70A83094FC5A/BuildTools_Full.exe C:\TEMP\vs_buildtools.exe
RUN C:\TEMP\vs_buildtools.exe `
    --quiet --norestart --nocache --wait `
    --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended`
    --add Microsoft.Component.MSBuild

# Install C++ Runtime v140
ADD https://download.microsoft.com/download/6/A/A/6AA4EDFF-645B-48C5-81CC-ED5963AEAD48/vc_redist.x64.exe C:\TEMP\cpp_runtime.exe
RUN C:\TEMP\cpp_runtime.exe /quiet /install

# Define the entry point for the docker container.
ENTRYPOINT ["cmd.exe"]

This one hangs prohibitively long (20+ minutes, if not forever) on step 4/7, running vs_buildtools.exe. If I simply do the ADD commands and then run them while in the container itself, they always just finish instantly and don't actually change the file system.

I have been able to get Visual Studio 2015 build tools installed correctly before, but it gives me an error about Microsoft.Cpp.Default.props not being found (similar to this StackOverflow question). It is looking for these in the v160 place, not the v140 as I'd want it to.

Can anyone spot something wrong with my Dockerfile, or suggest a better way to go about accomplishing this? I've tried many different things. I am fairly new to Docker, so maybe there is just some fundamental misunderstanding on my part. Thanks.

Upvotes: 0

Views: 902

Answers (1)

anden-akkio
anden-akkio

Reputation: 1247

I abandoned the approach of manually downloading the Build Tools + CPP Runtime, and instead used Chocolatey to get it set up. I'd previously tried it, but unbeknownst to me, internet inside Windows containers was broken then, so I fixed that (required a little bit of Hyper-V NAT Setup, and a powershell command, though both may not be necessary) and then Chocolatey worked perfectly for my use case and allowed me to compile the project.

Here's the dockerfile:

# escape=`

FROM mcr.microsoft.com/windows/servercore:ltsc2019

# Interpret as Powershell
# SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'Continue'; $verbosePreference='Continue';"]

# Install chocolatey
ADD https://chocolatey.org/install.ps1 C:\install.ps1
RUN @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex C:\install.ps1" 

# Install Visual C++ Build Tools, as per: https://chocolatey.org/packages/visualcpp-build-tools
RUN choco install visualcpp-build-tools -version 14.0.25420.1 -y

# Add msbuild to PATH
RUN setx /M PATH "%PATH%;C:\Program Files (x86)\MSBuild\14.0\bin"

# Test msbuild can be accessed without path
RUN msbuild -version

CMD [ "cmd.exe" ]

Upvotes: 2

Related Questions