From 8d4cee8a131f28c8b05df567450f549311ae59e7 Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 30 Sep 2020 10:49:57 -0700 Subject: [PATCH 1/2] fixes #20692 --- docs/core/compatibility/msbuild.md | 5 ++ ...eapp3_1-preprocessor-symbol-not-defined.md | 47 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 includes/core-changes/msbuild/5.0/netcoreapp3_1-preprocessor-symbol-not-defined.md diff --git a/docs/core/compatibility/msbuild.md b/docs/core/compatibility/msbuild.md index 38a0c58af4c2e..aa8cb0e599559 100644 --- a/docs/core/compatibility/msbuild.md +++ b/docs/core/compatibility/msbuild.md @@ -9,12 +9,17 @@ The following breaking changes are documented on this page: | Breaking change | Version introduced | | - | - | +| [NETCOREAPP3_1 preprocessor symbol is not defined when targeting .NET 5](#netcoreapp31-preprocessor-symbol-is-not-defined-when-targeting-net-5) | 5.0 | | [PublishDepsFilePath behavior change](#publishdepsfilepath-behavior-change) | 5.0 | | [Directory.Packages.props files is imported by default](#directorypackagesprops-files-is-imported-by-default) | 5.0 | | [Resource manifest file name change](#resource-manifest-file-name-change) | 3.0 | ## .NET 5.0 +[!INCLUDE [netcoreapp3_1-preprocessor-symbol-not-defined](../../../includes/core-changes/msbuild/5.0/netcoreapp3_1-preprocessor-symbol-not-defined.md)] + +*** + [!INCLUDE [publishdepsfilepath-behavior-change](../../../includes/core-changes/msbuild/5.0/publishdepsfilepath-behavior-change.md)] *** diff --git a/includes/core-changes/msbuild/5.0/netcoreapp3_1-preprocessor-symbol-not-defined.md b/includes/core-changes/msbuild/5.0/netcoreapp3_1-preprocessor-symbol-not-defined.md new file mode 100644 index 0000000000000..e0bdaf6ab2293 --- /dev/null +++ b/includes/core-changes/msbuild/5.0/netcoreapp3_1-preprocessor-symbol-not-defined.md @@ -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 + + From ce7b7d8a280d404f43af8f6a32431c03723d765e Mon Sep 17 00:00:00 2001 From: Genevieve Warren <24882762+gewarren@users.noreply.github.com> Date: Wed, 30 Sep 2020 11:00:03 -0700 Subject: [PATCH 2/2] fix bookmark --- docs/core/compatibility/msbuild.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/compatibility/msbuild.md b/docs/core/compatibility/msbuild.md index aa8cb0e599559..a6451476c9ce2 100644 --- a/docs/core/compatibility/msbuild.md +++ b/docs/core/compatibility/msbuild.md @@ -9,7 +9,7 @@ The following breaking changes are documented on this page: | Breaking change | Version introduced | | - | - | -| [NETCOREAPP3_1 preprocessor symbol is not defined when targeting .NET 5](#netcoreapp31-preprocessor-symbol-is-not-defined-when-targeting-net-5) | 5.0 | +| [NETCOREAPP3_1 preprocessor symbol is not defined when targeting .NET 5](#netcoreapp3_1-preprocessor-symbol-is-not-defined-when-targeting-net-5) | 5.0 | | [PublishDepsFilePath behavior change](#publishdepsfilepath-behavior-change) | 5.0 | | [Directory.Packages.props files is imported by default](#directorypackagesprops-files-is-imported-by-default) | 5.0 | | [Resource manifest file name change](#resource-manifest-file-name-change) | 3.0 |