forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
includes/core-changes/msbuild/5.0/netcoreapp3_1-preprocessor-symbol-not-defined.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
### NETCOREAPP3_1 preprocessor symbol is not defined when targeting .NET 5 | ||
|
||
In .NET 5.0 RC2 and later versions, projects no longer define preprocessor symbols for earlier versions, but only for the version that they target. This is the same behavior as .NET Core 1.0 - 3.1. | ||
|
||
#### Version introduced | ||
|
||
5.0 RC2 | ||
|
||
#### Change description | ||
|
||
In .NET 5.0 preview 7 through RC1, projects that target `net5.0` define both `NETCOREAPP3_1` and `NET5_0` preprocessor symbols. The intent behind this behavior change was that starting with .NET 5.0, conditional compilation [symbols would be cumulative](https://github.com/dotnet/designs/blob/main/accepted/2020/net5/net5.md#preprocessor-symbols). | ||
|
||
In .NET 5.0 RC2 and later, projects only define symbols for the target framework monikers (TFM) that it targets and not for any earlier versions. | ||
|
||
#### Reason for change | ||
|
||
The change from preview 7 was reverted due to customer feedback. Defining symbols for earlier versions surprised and confused customers, and some assumed it was a bug in the C# compiler. | ||
|
||
#### Recommended action | ||
|
||
Make sure that your `#if` logic doesn't assume that `NETCOREAPP3_1` is defined when the project targets `net5.0` or higher. Instead, assume that `NETCOREAPP3_1` is only defined when the project explicitly targets `netcoreapp3.1`. | ||
|
||
For example, if your project multitargets for .NET Core 2.1 and .NET Core 3.1 and you call APIs that were introduced in .NET Core 3.1, your `#if` logic should look as follows: | ||
|
||
```csharp | ||
#if NETCOREAPP2_1 || NETCOREAPP3_0 | ||
// Fallback behavior for old versions. | ||
#elif NETCOREAPP | ||
// Behavior for .NET Core 3.1 and later. | ||
#endif | ||
``` | ||
|
||
#### Category | ||
|
||
MSBuild | ||
|
||
#### Affected APIs | ||
|
||
N/A | ||
|
||
<!-- | ||
#### Affected APIs | ||
Not detectable via API analysis. | ||
--> |