38

I'm setting up various windows servers to host asp.net core apps, and I need to be able to determine if they have the asp.net hosting bundle installed.

https://docs.asp.net/en/latest/publishing/iis.html#install-the-net-core-windows-server-hosting-bundle says:

"Install the .NET Core Windows Server Hosting bundle on the server. The bundle will install the .NET Core Runtime, .NET Core Library, and the ASP.NET Core Module. The module creates the reverse-proxy between IIS and the Kestrel server."

I'm setting up a deployment, and I need to make sure my server is configured so I can run asp.net core apps.

I'm looking, basically, for a registry key or some other way to tell me if I should run the installer setup. (something like the way we'd tell if older versions of the framework are installed, like https://support.microsoft.com/en-us/kb/318785 does for earlier versions)

7 Answers 7

36

You can search Microsoft .NET Core 1.1.1 - Windows Server Hosting registry key under HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Updates\.NET Core path like screenshot below.

enter image description here

Also you can use PowerShell to determine the whether the key existed or not.

$DotNETCoreUpdatesPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Updates\.NET Core"
$DotNetCoreItems = Get-Item -ErrorAction Stop -Path $DotNETCoreUpdatesPath
$NotInstalled = $True
$DotNetCoreItems.GetSubKeyNames() | Where { $_ -Match "Microsoft .NET Core.*Windows Server Hosting" } | ForEach-Object {
    $NotInstalled = $False
    Write-Host "The host has installed $_"
}
If ($NotInstalled) {
    Write-Host "Can not find ASP.NET Core installed on the host"
}

And you can download sample from How to determine ASP.NET Core installation on a Windows Server by PowerShell.

5
  • 3
    If it is not installed, "Get-Item -ErrorAction Stop -Path $DotNETCoreUpdatesPath" will error and the script will never finish. The script needs to be surrounded by a try catch to work. I can edit the answer to include that if you like.
    – Kappacake
    Aug 16, 2018 at 14:10
  • Or, we can use Test-Path to check if $DotNETCoreUpdatesPath exists: $NotInstalled = $True $DotNETCoreUpdatesPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Updates\.NET Core" if (Test-Path $DotNETCoreUpdatesPath) { $DotNetCoreItems = Get-Item -ErrorAction Stop -Path $DotNETCoreUpdatesPath $NotInstalled = $True $DotNetCoreItems.GetSubKeyNames() | Where { $_ -Match "Microsoft .NET Core.*Windows Server Hosting" } | ForEach-Object { $NotInstalled = $False Write-Host "The host has installed $_" } (...) Nov 6, 2018 at 8:24
  • 2
    Not working for me for latest versions of the framework
    – Norcino
    Jul 3, 2020 at 7:12
  • 1
    I looked at programs and features to find Microsoft .NET 6.0.8 - Windows Server Hosting. This did not appear in the indicated registry location.
    – spacebread
    Oct 18, 2022 at 19:52
  • Check HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Updates\.NET
    – YUu
    Apr 17 at 2:24
26

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" }}
4
  • I like this answer, but having struggles with which of 64bit vs the 32bit powershell's get launched
    – BozoJoe
    Feb 19, 2018 at 23:51
  • 1
    How to execute this?
    – TiyebM
    Jun 1, 2019 at 13:37
  • 1
    this is only ok if you don't care which version is installed...
    – Dai Bok
    Mar 4, 2020 at 15:32
  • 2
    This command doesn't show the module even after it is installed. For me, this is because the module is actually called AspNetCoreModuleV2. Mar 6, 2021 at 8:48
14

If you have .NET Core CLI installed, you can try:

dotnet --list-runtimes

Which will print something like:

Microsoft.NETCore.App 3.0.0 [c:\program files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.0 [c:\program files\dotnet\shared\Microsoft.NETCore.App]

Reference: Microsoft doc

1
  • 4
    having a runtime on the machine does not mean IIS module has been installed Oct 5, 2021 at 14:15
4

If you're allowed to introduce constraints, one option is to only allow "Self-contained applications" since they do not require any additional installs. This also makes issues like 'what version is installed' go away.

If you need to support 'portable apps' you could simply execute the following to check if dotnet.exe is available:

where dotnet

You can then check the version:

dotnet --version

This would also allow you to check the version of .NET Core once that becomes a concern.

3

Note that the commands need to be run in powershell as Administrator.

Using the IISAdministration powershell module all modules can be listed as follows:

Import-Module IISAdministration

(Get-IISConfigSection -SectionPath "system.webServer/globalModules" `
| Get-IISConfigCollection).GetCollection() `
| select @{n="name";e={$_.GetAttributeValue("name")}}, `
         @{n="image";e={$_.GetAttributeValue("image")}}, `
         @{n="preCondition";e={$_.GetAttributeValue("preCondition")}}

So a test could be e.g.

$coreModule =
(Get-IISConfigSection -SectionPath "system.webServer/globalModules" `
| Get-IISConfigCollection).GetCollection() `
| where {$_.GetAttributeValue("name") -eq "AspNetCoreModuleV2" }

if (-not $coreModule)
{
    throw 'AspNetCoreModuleV2 is not installed'
}

Note at the time of this writing, both AspNetCoreModule and AspNetcoreModuleV2 are listed separately. Additional versions will likely show up in the future.

2

You can also double click DotNetCore.1.0.1-WindowsHosting.exe
If the .NET Core Windows Server Hosting bundle is already installed, the opening window will have :

  1. Modify Setup label
  2. Repair and Uninstall buttons

Repair and Uninstall buttons and a Modify Setup label.
Microsoft .NET Core 1.0.1 - Windows Server Hosting Setup already installed

1
  • Nice - no need to muck around with the registry or powershell. Aug 28, 2020 at 4:30
0

You can look at

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall{ab4f6e29-67a1-47d9-b2ab-43348a9bbae4}

and make sure that "Microsoft .NET Core 1.0.0 - Windows Server Hosting" is there

2
  • 4
    This will only detect that a specific installer was used... Probably it will no longer work when the next update is available. Jul 27, 2016 at 18:37
  • That's correct, I assume it will work along the same lines as detecting legacy .net versions: you grovel around in the registry looking for specific keys for specific versions of the framework.
    – weloytty
    Jul 28, 2016 at 11:50

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.