question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

net5.0 TFM defines both NET5_0 and NETCOREAPP3_1

See original GitHub issue

Description

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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:30 (23 by maintainers)

github_iconTop GitHub Comments

9reactions
sharwellcommented, Sep 4, 2020

It’s fine if the SDK defines both NETCOREAPP and NET5_0 (the former is allowed to be renamed to just NET but not required). However, the SDK must not define both NETCOREAPP3_1 and NET5_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.

7reactions
marcpopMSFTcommented, Sep 15, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found