Docker container to build a solution containing C++ and C# projects

Mark Shaw 6 Reputation points
2022-03-08T11:45:30.473+00:00

I had a docker file that used to successfully build a VS2019 solution containing C++ and C# projects. Then recently it stopped working.

I've been investigating and trying various combinations of docker images, without success.

I've now got a test VS2019 solution with one C++ hello world console project and one C# .NET5 hello world console project. This does not compile using the following docker file:

escape=`

FROM mcr.microsoft.com/dotnet/framework/sdk:4.8

SHELL ["cmd", "/S", "/C"]

Copy our Install script.

COPY Install.cmd C:\TEMP\

Download collect.exe in case of an install failure.

ADD https://aka.ms/vscollect.exe C:\TEMP\collect.exe

ADD https://aka.ms/vs/16/release/vs_buildtools.exe C:\Temp\vs_buildtools.exe
ADD https://aka.ms/vs/16/release/channel C:\Temp\VisualStudio.chman
RUN C:\Temp\vs_buildtools.exe --quiet --wait --norestart --nocache
--installPath C:\BuildTools --channelUri C:\Temp\VisualStudio.chman
--installChannelUri C:\Temp\VisualStudio.chman --add Microsoft.VisualStudio.Workload.VCTools;includeRecommended
--add Microsoft.Component.MSBuild `
|| IF "%ERRORLEVEL%"=="3010" EXIT 0

WORKDIR /src

ENTRYPOINT ["powershell.exe", "-NoLogo", "-ExecutionPolicy", "Bypass"] && CMD "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Commom7\Tools\VsDevCmd.bat"

The compiler error is C:\src\dockertest\ConsoleApplications\ConsoleApplicationCpp\ConsoleApplicationCpp.vcxproj(28,3): error MSB4019: The imp orted project "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\Microsoft.Cpp.D efault.props" was not found. Confirm that the expression in the Import declaration "C:\Program Files (x86)\Microsoft Vi sual Studio\2022\BuildTools\MSBuild\Microsoft\VC\v170\Microsoft.Cpp.Default.props" is correct, and that the file exist s on disk.

Bizarrely, this installs MSBuild for VS2022, despite the aka.ms/vs/16 link requesting VS2019.

Bizarrely, this installs .NET SDK 6.0.101, despite the FROM line asking for 4.8.

But the main problem is the VC tools are not installed. The folder C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft does not contain the VC folder.

I've followed various examples but they don't appear to work any more with the recent docker images.

I can only get the VCTools workload to install on the mcr.microsoft.com/windows/servercore:20H2 image. However, then that container does not have the .NET SDK.

Is there an example dockerfile that contains the build tools for a solution that contains C++ and C# projects?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,400 questions
.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
323 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,288 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,540 questions
{count} vote