Skip to content
Advertisement

Simplest way to build dotnet SDK project requiring net461 on MacOS

I have a dotnet SDK .sln (and a build.proj) with <TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>. It builds on Windows using Visual Studio and dotnet build, but I’d also like it to build as many other places as possible. What do I need to put in my README.md and/or what can I put in the project files to make it build on Rider and/or on from bash on a Mac?

Advertisement

Answer

(using .NET Core SDK) The simplest way to build for a .NET Framework TFM when running on either macOS or Linux using the .NET Core CLI, is to utilize the .NET Framework Targeting Pack Nuget Packages from Microsoft (currently in preview):

These packages enable building .NET Framework projects on any machine with at least MSBuild or the .NET Core SDK installed.

The following scenarios and benefits are enabled for .NET Framework projects:

  • Build without requiring admin operations to install pre-requisites such as Visual Studio or .NET Framework targeting packs.
  • Build libraries on any operating system supported by the .NET Core SDK.
  • Build Mono-based projects.

You may either include the Microsoft.NETFramework.ReferenceAssemblies metapackage; or use just the specific package, which is in your case Microsoft.NETFramework.ReferenceAssemblies.net461.

Add the package to the *.csproj or your Directory.Build.props:

<Project>
  <ItemGroup>
    <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
  </ItemGroup>
</Project>

Note: The PrivateAssets attribute controls which dependency assets will be consumed but won’t flow to the parent project. See the docs.

Update

This is no longer required using the .NET 5 SDK (e.g. 5.0.100), which will now automatically add the PackageReference to the ReferenceAssemblies for .NET Framework.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement