title: Building a WinForms C# application with Docker .NET Core image results to an error : .NETFramework,Version=v4.6.1 were not found
body: <p>I'm trying to build a C# project, using WinForms (if that helps), <strong>under GNU/Linux</strong> using Docker and .NET Core Docker image, as explained in <a href="https://docs.microsoft.com/en-us/dotnet/core/docker/build-container" rel="nofollow noreferrer">the documentation</a>. Disclaimer : I'm not an expert in C# or .NET.</p>
  
  <p>My project is structured like this :</p>
  
  <pre><code>.
  ├── MyProject.sln
  └── MyProject
  │   ├── Package1
  │   |   └── ...
  │   ├── Package2
  │   |   └── ...
  │   └── MyProject.csproj
  └── MyProjectUnitTests
      ├── ...
      └── MyProjectUnitTests.csproj
  </code></pre>
  
  <p>In both <code>.csproj</code> files, the target framework version is <code>v4.6.1</code> :</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;!--&gt;...&lt;--&gt;
    &lt;PropertyGroup&gt;
      &lt;!--&gt;...&lt;--&gt;
      &lt;TargetFrameworkVersion&gt;v4.6.1&lt;/TargetFrameworkVersion&gt;
    &lt;/PropertyGroup&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>I'm using the following <code>Dockerfile</code>, like <a href="https://github.com/dotnet/dotnet-docker/blob/17c1eec/samples/complexapp/Dockerfile" rel="nofollow noreferrer">in this official example</a> :</p>
  
  <pre><code>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
  </code></pre>
  
  <p>The download of dependencies works correctly (<code>dotnet restore</code>), but the last command (<code>dotnet build</code>) failed with the following error :</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>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 <code>mcr.microsoft.com/dotnet/core/sdk:3.1.201-buster</code> image, to avoid installing it myself.</p>
  
  <p>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 <code>.csproj</code> files?
  Some says that I should install <a href="https://www.mono-project.com/" rel="nofollow noreferrer"><code>Mono</code></a>, but I've tried to install <code>mono-complete</code> package and still got the same error.</p>
  
  <p>Does someone have any idea (it may be just a small mistake, since I don't know .NET environment very well) ? </p>
  
  <h3>Edit : build fails with .NET Core image, but succeed with mono</h3>
  
  <p>I forgot to mention it but the build inside a Docker container works with the base image <code>mono:6.8.0.96</code> and the following Dockerfile :</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>
  
  <p>To avoid this refactoring, I'd like to use the Microsoft base images instead of Mono if possible.</p>