I'm trying to build a C# project, using WinForms (if that helps), under GNU/Linux using Docker and .NET Core Docker image, as explained in the documentation. Disclaimer : I'm not an expert in C# or .NET.
My project is structured like this :
.
├── MyProject.sln
└── MyProject
│ ├── Package1
│ | └── ...
│ ├── Package2
│ | └── ...
│ └── MyProject.csproj
└── MyProjectUnitTests
├── ...
└── MyProjectUnitTests.csproj
In both .csproj files, the target framework version is v4.6.1 :
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-->...<-->
<PropertyGroup>
<!-->...<-->
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>
</Project>
I'm using the following Dockerfile, like in this official example :
FROM mcr.microsoft.com/dotnet/core/sdk:3.1.201-buster
WORKDIR /app
# copy all files necessary to resolve dependencies
COPY MyProject.sln .
COPY MyProject/MyProject.csproj MyProject/
COPY MyProjectUnitTests/MyProjectUnitTests.csproj MyProjectUnitTests/
# resolve dependencies
RUN dotnet restore --verbosity normal
# copy all files
COPY . .
RUN dotnet build
The download of dependencies works correctly (dotnet restore), but the last command (dotnet build) failed with the following error :
Build FAILED.
/usr/share/dotnet/sdk/3.1.201/Microsoft.Common.CurrentVersion.targets(1177,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.6.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [/MyProjectUnitTests/MyProjectUnitTests.csproj]
/usr/share/dotnet/sdk/3.1.201/Microsoft.Common.CurrentVersion.targets(1177,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.6.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [/MyProject/MyProject.csproj]
0 Warning(s)
2 Error(s)
I don't understand the errors. The errors redirects me to a Microsoft website where I can find explanations for downloading and installing .NET Core 3.1.201, but that's exactly why I'm using the mcr.microsoft.com/dotnet/core/sdk:3.1.201-buster image, to avoid installing it myself.
The project seems to build fine on Windows (without Docker), but I don't have any Windows machine available. Am I missing something in the .csproj files?
Some says that I should install Mono, but I've tried to install mono-complete package and still got the same error.
Does someone have any idea (it may be just a small mistake, since I don't know .NET environment very well) ?
Edit : build fails with .NET Core image, but succeed with mono
I forgot to mention it but the build inside a Docker container works with the base image mono:6.8.0.96 and the following Dockerfile :
FROM mono:6.8.0.96
WORKDIR /app
# copy all files necessary to resolve dependencies
COPY MyProject.sln .
COPY MyProject/MyProject.csproj MyProject/
COPY MyProjectUnitTests/MyProjectUnitTests.csproj MyProjectUnitTests/
# resolve dependencies
RUN nuget restore
# copy all files
COPY . .
RUN msbuild
As @LexLi pointed out in a comment, some code needs to be refactored (notably WPF API calls because Mono doesn't support it), but the build succeeds with Mono.
To avoid this refactoring, I'd like to use the Microsoft base images instead of Mono if possible.
msbuildto compile the projects. However, WinForms on Mono is never a completed attempt, so you shouldn't expect it works all the time. 2) WinForms on .NET Framework or .NET Core is Windows only, so like the others commented, you can only use a Windows machine (or Windows Docker image) to compile it, with the right tooling (msbuildordotnetCLI).