How to programmatically check the .NET Core Runtime version installed on my machine from a .NET Framework app?

Viewed 2223

I am writing an application in C#. The application is a console application targeting .NET 4.7. From that application I want to programmatically check if .NET Core 3.1.300 runtime is installed. If not then I want to install it. How to do that ? So far I haven't found any API to check the installed .net core runtime.

2 Answers

To save you the trouble you have to query these locations in the registry:

For x64 versions

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\dotnet\Setup\InstalledVersions\x64\sharedfx\Microsoft.NETCore.App

For x86 versions

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\dotnet\Setup\InstalledVersions\x86\sharedfx\Microsoft.NETCore.App

This may change in the future but from what i've seen and from my machine all the versions are logged in these locations.

Regarding Linux

from the docs link that Olivier Rogier suggested you can check for these folders:

dotnet executable /home/user/share/dotnet/dotnet

.NET SDK /home/user/share/dotnet/sdk/{version}/

.NET Runtime /home/user/share/dotnet/shared/{runtime-type}/{version}/

Yes. From .Net Core 3 you can use:

var netCoreVer = System.Environment.Version; 
var runtimeVer = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription; 
Related