3

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.

Ayan
  • 115
  • 2
  • 10
  • how about using the `Registry` ? – HMZ Jul 13 '20 at 12:03
  • @HMZ How to do that ? Any pointer to start ? – Ayan Jul 13 '20 at 12:04
  • see here its already been asked : [Github](https://github.com/dotnet/runtime/issues/2953) – HMZ Jul 13 '20 at 12:05
  • Does this answer your question? [Programmatically get current running version of dotnet core runtime](https://stackoverflow.com/questions/49309108/programmatically-get-current-running-version-of-dotnet-core-runtime) –  Jul 13 '20 at 12:14
  • Also that: [Getting the .NET Core Runtime Version in a Running Application](https://weblog.west-wind.com/posts/2018/Apr/12/Getting-the-NET-Core-Runtime-Version-in-a-Running-Application) –  Jul 13 '20 at 12:14
  • https://stackoverflow.com/questions/38567353/how-to-determine-if-net-core-is-installed – zia khan Jul 13 '20 at 12:15
  • @OlivierRogier he's running on .net framework and wants to check the current .net core version. – HMZ Jul 13 '20 at 12:16
  • @HMZ Thus the title is misleading. So that can help: [How to check that .NET Core is already installed](https://learn.microsoft.com/dotnet/core/install/how-to-detect-installed-versions) –  Jul 13 '20 at 12:17

2 Answers2

4

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}/

HMZ
  • 2,949
  • 1
  • 19
  • 30
  • @HMZ Which one is a better option according to you ? Checking the dotnet folder or checking the registry ? – Ayan Jul 13 '20 at 12:50
  • 1
    @Ayan for windows you check the registry and for linux you check for the folders i mentioned above. in windows i would choose the registry over the dotnet folder. its faster and simpler – HMZ Jul 13 '20 at 12:53
1

Yes. From .Net Core 3 you can use:

var netCoreVer = System.Environment.Version; 
var runtimeVer = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription; 
D A
  • 1,724
  • 1
  • 8
  • 19
  • 1
    This is useful for examining the _running application's_ underlying framework, but doesn't answer the question as asked. – mklement0 Mar 31 '21 at 14:47