-
-
Save richlander/3f9bd226acaa3c8e080e1945e7407bc3 to your computer and use it in GitHub Desktop.
Testing for .NET family
This file contains hidden or 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
| <Project Sdk="Microsoft.NET.Sdk"> | |
| <PropertyGroup> | |
| <OutputType>Exe</OutputType> | |
| <TargetFrameworks>netcoreapp3.1;net5.0;net48</TargetFrameworks> | |
| </PropertyGroup> | |
| </Project> |
This file contains hidden or 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
| using System; | |
| using System.Runtime.InteropServices; | |
| namespace frameworkdescription | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| Console.WriteLine($"{nameof(Environment.Version)}: {Environment.Version}"); | |
| Console.WriteLine($"{nameof(RuntimeInformation.FrameworkDescription)}: {RuntimeInformation.FrameworkDescription}"); | |
| if (Environment.Version.Major >= 5) | |
| { | |
| Console.WriteLine($"This is .NET {Environment.Version}"); | |
| } | |
| // This test for .NET Core only works for 3.0+ | |
| // Context: https://github.com/dotnet/runtime/issues/12124 | |
| else if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Core")) | |
| { | |
| Console.WriteLine($"This is .NET Core {Environment.Version}"); | |
| } | |
| else if (Environment.Version.Major < 5) | |
| { | |
| Console.WriteLine($"This is .NET Framework {Environment.Version}"); | |
| } | |
| // Some folks want a simple "is .NET Core" check. | |
| var isDotnetCore = Environment.Version.Major >= 5 || RuntimeInformation.FrameworkDescription.StartsWith(".NET Core"); | |
| if (isDotnetCore) | |
| { | |
| Console.WriteLine("This is .NET Core"); | |
| } | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results: