net5.0 TFM defines both NET5_0 and NETCOREAPP3_1
See original GitHub issueDescription
When building a project that cross compiles between net5.0 and netcoreapp3.1 there’s an ordering problem with the #if
’s. If the NETCOREAPP3_1 condition is put first then the net5.0 TFM will compile using it, but if the NET5_0 condition is first then that is choosen.
Configuration
5.0.100-preview.8.20417.9 SDK
Windows 10 2004 (19041.450) x64
Regression?
Yes. This was working in prior preview SDKs when using NETCOREAPP5_0.
Other information
Program.cs:
using System;
using System.Runtime.CompilerServices;
namespace TfmConsole
{
class Program
{
static void Main(string[] args)
{
Broken();
Fixed();
}
static void Broken()
{
Console.WriteLine("Hello Broken World! " + Environment.Version);
#if NETCOREAPP3_1
Console.WriteLine("NETCOREAPP3_1");
#elif NET5_0
Console.WriteLine("NET5_0");
#elif NETCOREAPP5_0
Console.WriteLine("NETCOREAPP5_0");
#else
#error A target framework was added to the project and needs to be added to this condition.
#endif
}
static void Fixed()
{
Console.WriteLine("Hello Fixed World! " + Environment.Version);
#if NET5_0
Console.WriteLine("NET5_0");
#elif NETCOREAPP5_0
Console.WriteLine("NETCOREAPP5_0");
#elif NETCOREAPP3_1
Console.WriteLine("NETCOREAPP3_1");
#else
#error A target framework was added to the project and needs to be added to this condition.
#endif
}
}
}
csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net5.0;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
</Project>
Output:
C:\temp\TfmConsole\TfmConsole>dotnet run --framework netcoreapp3.1
Hello Broken World! 3.1.7
NETCOREAPP3_1
Hello Fixed World! 3.1.7
NETCOREAPP3_1
C:\temp\TfmConsole\TfmConsole>dotnet run --framework net5.0
Hello Broken World! 5.0.0
NETCOREAPP3_1
Hello Fixed World! 5.0.0
NET5_0
C:\temp\TfmConsole\TfmConsole>dotnet run --framework netcoreapp5.0
Hello Broken World! 5.0.0
NETCOREAPP3_1
Hello Fixed World! 5.0.0
NET5_0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:30 (23 by maintainers)
Top Results From Across the Web
Target frameworks in SDK-style projects - .NET
The net5.0 , net6.0 , and net7.0 TFMs include technologies that work across different platforms. Specifying an OS-specific TFM makes APIs ...
Read more >.NET 5: Merging .NET Core and .NET Standard with New ...
Both formats are XML-based, and both have a Project root element. ... But there will be a new TFM that is called net5.0...
Read more >Experimenting with .NET 5 Target Framework Names and the ...
Currently we're using net5.0-windows and as we saw this maps to version 7 of the Windows platform. If we change the tfm to...
Read more >How to multitarget .NET 5 and .NET Core 3.1 while still ...
My project multitargets .netstandard2.0 , .netcoreapp3.1 and .net5.0 , with SDK-specific code defined out. For compatibility reasons ...
Read more >Five Things You Should Know About .NET 5
This set of APIs is identified by the net5.0 Target Framework Moniker (TFM), which is the token you set in your .NET project...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s fine if the SDK defines both
NETCOREAPP
andNET5_0
(the former is allowed to be renamed to just NET but not required). However, the SDK must not define bothNETCOREAPP3_1
andNET5_0
. Doing so would break the entire mental model of the feature and we’ll be stuck with the ugly workaround of writing custom build tooling that fails the build if a user fails to manually remove the extraneous definition.We’ve reviewed the feedback both from external and internal customers and for net5.0, we will remove the change that defines NETCOREAPP3_1 for this release. @terrajobst will own developing a new proposal for a future SDK release. For now, customers can use
#if NET
to mean .net 5 and higher.Based on our analysis of existing projects, most customers use these symbols as >= so we want to provide that option. However, we recognize that changing the previous behavior that existed for 3.1 and before will impact some customers and cause confusion.
Thanks all for the feedback.