Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to programmatically check the .Net sdk version

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.

like image 641
Faisal Sajjad Avatar asked Mar 19 '26 23:03

Faisal Sajjad


1 Answers

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.

like image 165
mm8 Avatar answered Mar 21 '26 15:03

mm8



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!