Besides the version-specific directives such as NETSTANDARD2_0
, the Target frameworks documentation lists the following preprocessor symbols:
NETFRAMEWORK
NETSTANDARD
NETCOREAPP
...and NETMF
for .NET Micro Framework, WP
for Windows Phone, and UAP
for Universal Windows Platform.
Here is an example .csproj
:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.5;netstandard2.0;net48;netcoreapp3.0</TargetFrameworks>
</PropertyGroup>
</Project>
and C# class:
namespace ClassLibrary1
{
public class Class1
{
public void Test()
{
#if NETFRAMEWORK
System.Console.WriteLine(".NET Framework");
#elif NETCOREAPP
System.Console.WriteLine(".NET Core");
#elif NETSTANDARD
System.Console.WriteLine(".NET Standard");
#endif
}
}
}
Here's .NET Core 3.0 selected (see top left), with the NETCOREAPP
region 'live' and the others greyed out:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…