Don't define NETCOREAPP3_1 when targeting .NET 5 #20692
Labels
breaking-change
Indicates a .NET Core breaking change
🏁 Release: .NET 5
Work items for the .NET 5 release
Don't define NETCOREAPP3_1 when targeting .NET 5
.NET 5 will now have the same behavior for defining preprocessor symbols as previous releases of .NET Core, that is, we only define symbols for what the project is actually targeting and no longer include defines for earlier versions.
Version introduced
.NET 5 RC2
Old behavior
Since .NET 5 Preview 7, targeting
net5.0
defined bothNETCOREAPP3_1
andNET5_0
preprocessor symbols. The intent was that starting with .NET 5, conditional compilation symbols would be accumulative.New behavior
We'll revert this change which will make the behavior consistent with how preprocessor symbols were defined in previous releases of .NET Core (1.0 - 3.1).
Reason for change
Customer feedback. The new behavior was surprising and caused confusion on how to accommodate it. People assumed this was a bug in the C# compiler.
Recommended action
Ensure your
#if
logic doesn't assume thatNETCOREAPP3_1
is defined when the project is targetingnet5.0
or higher. Instead, assume thatNETCOREAPP3_1
is only defined when the project targetsnetcoreapp3.1
exactly.For example, if your project multitargets for .NET Core 2.1 and .NET Core 3.1 and you need to call APIs that were introduced in .NET Core 3.1, your
#if
logic should look as follows:Issue metadata
The text was updated successfully, but these errors were encountered: