Skip to content

net5.0 TFM defines both NET5_0 and NETCOREAPP3_1 #13377

@Tratcher

Description

@Tratcher

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions