I'm attempting to use an if compiler directive to conditionally include some code that is required for earlier versions of the .Net Framework, but not later versions.
I've used the following references from MSDN, the #if compiler directive reference, and the Target Frameworks reference.
I'm authoring a .Net 4.5.1 application, but the NET451 symbol doesn't appear to be defined, and neither do any others.
I've adapted the example from the Target Frameworks MSDN article to include all framework symbols, so I can see which one is defined.
#if NET20
Console.WriteLine("Target framework: NET20");
#elif NET35
Console.WriteLine("Target framework: NET35");
#elif NET40
Console.WriteLine("Target framework: NET40");
#elif NET45
Console.WriteLine("Target framework: NET45");
#elif NET451
Console.WriteLine("Target framework: NET451");
#elif NET452
Console.WriteLine("Target framework: NET452");
#elif NET46
Console.WriteLine("Target framework: NET46");
#elif NET461
Console.WriteLine("Target framework: NET461");
#elif NET462
Console.WriteLine("Target framework: NET462");
#elif NET47
Console.WriteLine("Target framework: NET47");
#elif NET471
Console.WriteLine("Target framework: NET471");
#elif NET472
Console.WriteLine("Target framework: NET472");
#elif NETSTANDARD1_0
Console.WriteLine("Target framework: NETSTANDARD1_0");
#elif NETSTANDARD1_1
Console.WriteLine("Target framework: NETSTANDARD1_1");
#elif NETSTANDARD1_2
Console.WriteLine("Target framework: NETSTANDARD1_2");
#elif NETSTANDARD1_3
Console.WriteLine("Target framework: NETSTANDARD1_3");
#elif NETSTANDARD1_4
Console.WriteLine("Target framework: NETSTANDARD1_4");
#elif NETSTANDARD1_5
Console.WriteLine("Target framework: NETSTANDARD1_5");
#elif NETSTANDARD1_6
Console.WriteLine("Target framework: NETSTANDARD1_6");
#elif NETSTANDARD2_0
Console.WriteLine("Target framework: NETSTANDARD2_0");
#elif NETCOREAPP1_0
Console.WriteLine("Target framework: NETCOREAPP1_0");
#elif NETCOREAPP1_1
Console.WriteLine("Target framework: NETCOREAPP1_1");
#elif NETCOREAPP2_0
Console.WriteLine("Target framework: NETCOREAPP2_0");
#elif NETCOREAPP2_1
Console.WriteLine("Target framework: NETCOREAPP2_1");
#elif NETCOREAPP2_2
Console.WriteLine("Target framework: NETCOREAPP2_2");
#else
Console.WriteLine("Could not tell which framework we're using.");
#endif
The resulting output is "Could not tell which framework we're using".
Am I doing something wrong? Is the documentation incorrect? Or have I found a bug?