Detect my version of dotnet

How can I test a C # application, which version of dotnet is used by the application?

+6
c #
source share
4 answers

Use Environment.Version - it gives the exact version of .NET that launches the application.

Returns a Version object that describes the major, minor, string, and revision numbers of the common language runtime.


To find out which version of the framework is installed, see this question and answers. In the walnut shell, you will need to insert it into the registry.

+12
source share

You can use:

 Environment.Version 

to get the version number of the .NET runtime.

+6
source share

Create a console application add this class and run it

  using Microsoft.Win32; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { public class GetDotNetVersion { public static void Get45PlusFromRegistry() { const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\"; using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey)) { if (ndpKey != null && ndpKey.GetValue("Release") != null) { Console.WriteLine(".NET Framework Version: " + CheckFor45PlusVersion((int)ndpKey.GetValue("Release"))); } else { Console.WriteLine(".NET Framework Version 4.5 or later is not detected."); } } } // Checking the version using >= will enable forward compatibility. private static string CheckFor45PlusVersion(int releaseKey) { if (releaseKey >= 394802) return "4.6.2 or later"; if (releaseKey >= 394254) { return "4.6.1"; } if (releaseKey >= 393295) { return "4.6"; } if ((releaseKey >= 379893)) { return "4.5.2"; } if ((releaseKey >= 378675)) { return "4.5.1"; } if ((releaseKey >= 378389)) { return "4.5"; } // This code should never execute. // that 4.5 or later is installed. return "No 4.5 or later version detected"; } } // Calling the GetDotNetVersion.Get45PlusFromRegistry method produces // output like the following: // .NET Framework Version: 4.6.1 } 
0
source share

In your Visual Studio, go to Tools-> Package Management Nutget-> Package Manager Console Type in dotnet -version And here you go!

0
source share

All Articles