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?
(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.
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.
In order to build via bash on a vanilla Mac, the minimal steps seem to be:
<Project> <PropertyGroup> <IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))'== 'true'">true</IsOSX> </PropertyGroup> <PropertyGroup Condition=" '$(IsOSX)' == 'true' "> <FrameworkPathOverride>/Library/Frameworks/Mono.framework/Versions/Current/Commands/../lib/mono/4.6.1-api</FrameworkPathOverride> </PropertyGroup> </Project>
dotnet build SolutionFileName.sln
should now workIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With