Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the preprocessor symbols defined for .Net 5.0?

Tags:

c#

.net-5

What would you use in a #if when targeting .Net 5.0?

i.e. for the other frameworks

.NET Framework

NETFRAMEWORK, NET20, NET35, NET40, NET45, NET451, NET452, NET46, NET461, NET462, NET47, NET471, NET472, NET48

.NET Standard

NETSTANDARD, NETSTANDARD1_0, NETSTANDARD1_1, NETSTANDARD1_2, NETSTANDARD1_3, NETSTANDARD1_4, NETSTANDARD1_5, NETSTANDARD1_6, NETSTANDARD2_0, NETSTANDARD2_1

.NET Core

NETCOREAPP, NETCOREAPP1_0, NETCOREAPP1_1, NETCOREAPP2_0, NETCOREAPP2_1, NETCOREAPP2_2, NETCOREAPP3_0, NETCOREAPP3_1

like image 639
Sprotty Avatar asked Jul 14 '20 10:07

Sprotty


2 Answers

If you set the build output to "detailed" and try this today, you should see something like (among the rest of the output - near a csc.exe mention):

/define:TRACE;DEBUG;NETCOREAPP;NETCOREAPP5_0

so: NETCOREAPP5_0 is what you're looking for - but: whether this stays the same at launch may change. You can repeat the same process at a later date to find out.

like image 152
Marc Gravell Avatar answered Oct 22 '22 16:10

Marc Gravell


The preprocessor definitions changed in dotnet/sdk#12124 to fit this design before .NET 5 was released. The released version defines:

NETCOREAPP
NET5_0

This is now also documented in #if (C# reference). It does not define NETCOREAPP5_0 anymore.

like image 33
Kevinoid Avatar answered Oct 22 '22 16:10

Kevinoid