How to multitarget .NET 5 and .NET Core 3.1 while still building on .NET Core 3.0 SDK

Viewed 1569

I am trying to upgrade my project to support .NET 5 while still building on a .NET Core 3.1 toolset.

I tried to add the .NET 5 TFM (.net5.0) to my target frameworks like so.

<TargetFrameworks>netcoreapp3.0;netcoreapp3.1;net5.0</TargetFrameworks>

Unfortunately, this causes the build to fail when running on a machine with only .NET Core 3.1 toolset installed.

error MSB3971: The reference assemblies for ".NETFramework,Version=v5.0" were not found. You might be using an older .NET SDK to target .NET 5.0 or higher. Update Visual Studio and/or your .NET SDK.

I'm trying to find a condition so I can target net5.0 only if it is available, but documentation is sparse.

1 Answers

That's not really possible.

A new SDK (eg, 5.0) can target older runtimes via older TargetFrameworks (netcoreapp2.1, netcoreapp3.1, etc).

An older SDK can not target newer runtimes via new TargetFrameworks.

Related