How to Determine If .Net Core Is Installed

How to determine if .NET Core is installed

Great question, and the answer is not a simple one. There is no "show me all .net core versions" command, but there's hope.

EDIT:

I'm not sure when it was added, but the info command now includes this information in its output. It will print out the installed runtimes and SDKs, as well as some other info:

dotnet --info

If you only want to see the SDKs: dotnet --list-sdks

If you only want to see installed runtimes: dotnet --list-runtimes

I'm on Windows, but I'd guess that would work on Mac or Linux as well with a current version.

Also, you can reference the .NET Core Download Archive to help you decipher the SDK versions.


OLDER INFORMATION:
Everything below this point is old information, which is less relevant, but may still be useful.

See installed Runtimes:

Open C:\Program Files\dotnet\shared\Microsoft.NETCore.App in Windows Explorer

See installed SDKs:

Open C:\Program Files\dotnet\sdk in Windows Explorer

(Source for the locations: A developer's blog)


In addition, you can see the latest Runtime and SDK versions installed by issuing these commands at the command prompt:

dotnet Latest Runtime version is the first thing listed. DISCLAIMER: This no longer works, but may work for older versions.

dotnet --version Latest SDK version DISCLAIMER: Apparently the result of this may be affected by any global.json config files.


On macOS you could check .net core version by using below command.

ls /usr/local/share/dotnet/shared/Microsoft.NETCore.App/

On Ubuntu or Alpine:

ls /usr/share/dotnet/shared/Microsoft.NETCore.App/

It will list down the folder with installed version name.

How to determine if .NET Core Runtime is installed from CentOs 7

dotnet --info will show the version of the SDK (if installed), the names and versions of all the runtimes that are installed, including the .NET Core runtime and ASP.NET Core runtime.

$ dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.1.301
Commit: 59524873d6

Runtime Environment:
OS Name: fedora
OS Version: 28
OS Platform: Linux
RID: fedora.28-x64
Base Path: /usr/lib64/dotnet/sdk/2.1.301/

Host (useful for support):
Version: 2.1.1
Commit: N/A

.NET Core SDKs installed:
2.1.202 [/usr/lib64/dotnet/sdk]
2.1.301 [/usr/lib64/dotnet/sdk]

.NET Core runtimes installed:
Microsoft.NETCore.App 2.0.9 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.1 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

If you only care about the runtime (.NET Core and ASP.NET Core) versions, you can use dotnet --list-runtimes. This requires a recent-enough version of .NET Core:

$ dotnet --list-runtimes
Microsoft.NETCore.App 2.0.9 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.1 [/usr/lib64/dotnet/shared/Microsoft.NETCore.App]

I don't have the ASP.NET Core runtime packages installed, so it only shows me the .NET Core runtime.

How to determine if asp.net core has been installed on a windows server

You can use powershell to check if the hosting module is registered with IIS

In the local powershell session

Import-module WebAdministration
$vm_dotnet_core_hosting_module = Get-WebGlobalModule | where-object { $_.name.ToLower() -eq "aspnetcoremodule" }
if (!$vm_dotnet_core_hosting_module)
{
throw ".Net core hosting module is not installed"
}

If you want to do in the remote session replace first 2 lines with

Invoke-Command -Session $Session {Import-module WebAdministration}
$vm_dotnet_core_hosting_module = Invoke-Command -Session $Session {Get-WebGlobalModule | where-object { $_.name.ToLower() -eq "aspnetcoremodule" }}

How to find ASP.Net Core version?

To check which .NET Core Version is installed you can run one of the following commands on the command prompt.

dotnet --version      // Display .NET Core SDK version.

dotnet --info //Display .NET Core information.

dotnet --list-runtimes // Display the installed runtimes.

dotnet --list-sdks // Display the installed SDKs.

Also, you can view all .NET Core versions Installed on the system by navigating to the installation folder on below path.

%ProgramFiles%\dotnet\sdk

Check if .NET 5.0 is installed in Inno Setup

Based on:

  • How to get an output of an Exec'ed program in Inno Setup?
  • How to check that .NET is already installed

You can do:

[Code]

function IsDotNetInstalled(DotNetName: string): Boolean;
var
Cmd, Args: string;
FileName: string;
Output: AnsiString;
Command: string;
ResultCode: Integer;
begin
FileName := ExpandConstant('{tmp}\dotnet.txt');
Cmd := ExpandConstant('{cmd}');
Command := 'dotnet --list-runtimes';
Args := '/C ' + Command + ' > "' + FileName + '" 2>&1';
if Exec(Cmd, Args, '', SW_HIDE, ewWaitUntilTerminated, ResultCode) and
(ResultCode = 0) then
begin
if LoadStringFromFile(FileName, Output) then
begin
if Pos(DotNetName, Output) > 0 then
begin
Log('"' + DotNetName + '" found in output of "' + Command + '"');
Result := True;
end
else
begin
Log('"' + DotNetName + '" not found in output of "' + Command + '"');
Result := True;
end;
end
else
begin
Log('Failed to read output of "' + Command + '"');
end;
end
else
begin
Log('Failed to execute "' + Command + '"');
Result := False;
end;
DeleteFile(FileName);
end;

And it use it like:

if IsDotNetInstalled('Microsoft.NETCore.App 5.0.') then // ...


Related Topics



Leave a reply



Submit