I'm using the WPF application. I want to check programmatically whether .Net SDK is installed or not. I'm getting the list of SDK using the below code. But the problem is registry may change in the future.
RegistryKey ndpKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\dotnet\Setup\InstalledVersions\x64\sdk");
var names = ndpKey.GetValueNames();
I also run the following code but it gives me a .NET runtime version.
var netCoreVersion = Environment.Version;
var runtimeVersion= RuntimeInformation.FrameworkDescription;
Is there any way programmatically I can find whether .Net SDK is installed or not.
CodePudding user response:
Is there any way programmatically I can find whether .Net SDK is installed or not.
There is no API do to this so either stick with your approach of looking in the registry or invoke the dotnet command-line tool programmatically and capture its output:
Process process = new Process();
process.StartInfo.FileName = "dotnet.exe";
process.StartInfo.Arguments = "--version";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
string version = process.StandardOutput.ReadToEnd()?.TrimEnd();
process.WaitForExit();
You probably also want to catch exceptions to handle cases where the tool isn't installed.
CodePudding user response:
From your code, you can do this.
var netCoreVer = System.Environment.Version;
var runtimeVer = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
