如何确定 asp.net 核心是否已安装在 windows 服务器上
How to determine if asp.net core has been installed on a windows server
我正在设置各种 windows 服务器来托管 asp.net 核心应用程序,我需要能够确定它们是否安装了 asp.net 托管包。
"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."
我正在设置部署,我需要确保我的服务器已配置,以便我可以 运行 asp.net 核心应用程序。
基本上,我正在寻找注册表项或其他方式来告诉我是否应该 运行 安装程序设置。 (类似于我们判断是否安装了旧版本框架的方式,比如
https://support.microsoft.com/en-us/kb/318785
适用于早期版本)
如果您被允许引入约束,一种选择是只允许 "Self-contained applications",因为它们不需要任何额外的安装。这也使得 'what version is installed' 之类的问题消失了。
如果您需要支持 'portable apps',您可以简单地执行以下命令来检查 dotnet.exe 是否可用:
where dotnet
然后您可以查看版本:
dotnet --version
一旦出现问题,您还可以检查 .NET Core 的版本。
你可以看看
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall{ab4f6e29-67a1-47d9-b2ab-43348a9bbae4}
并确保 "Microsoft .NET Core 1.0.0 - Windows Server Hosting" 在那里
也可以双击DotNetCore.1.0.1-WindowsHosting.exe
如果 .NET Core Windows 服务器托管捆绑包已经安装,则开头 window 将具有:
- 修改设置标签
- 修复和卸载按钮
修复和卸载按钮以及修改安装标签。
您可以使用 powershell 检查托管模块是否已在 IIS 中注册
在本地 powershell 会话中
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"
}
如果您想在远程会话中执行,请将前两行替换为
Invoke-Command -Session $Session {Import-module WebAdministration}
$vm_dotnet_core_hosting_module = Invoke-Command -Session $Session {Get-WebGlobalModule | where-object { $_.name.ToLower() -eq "aspnetcoremodule" }}
您可以在 HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Updates\.NET Core
路径下搜索 Microsoft .NET Core 1.1.1 - Windows Server Hosting
注册表项,如下面的屏幕截图。
您也可以使用 PowerShell 来确定密钥是否存在。
$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"
}
您可以从 How to determine ASP.NET Core installation on a Windows Server by PowerShell 下载示例。
请注意,命令需要以管理员身份在 powershell 中 运行。
使用IISAdministration powershell module可以列出所有模块如下:
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")}}
所以测试可以是
$coreModule =
(Get-IISConfigSection -SectionPath "system.webServer/globalModules" `
| Get-IISConfigCollection).GetCollection() `
| where {$_.GetAttributeValue("name") -eq "AspNetCoreModuleV2" }
if (-not $coreModule)
{
throw 'AspNetCoreModuleV2 is not installed'
}
请注意,在撰写本文时,AspNetCoreModule
和 AspNetcoreModuleV2
均单独列出。将来可能会出现其他版本。
如果你安装了.NET Core CLI,你可以试试:
dotnet --list-runtimes
这将打印如下内容:
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]
我正在设置各种 windows 服务器来托管 asp.net 核心应用程序,我需要能够确定它们是否安装了 asp.net 托管包。
"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."
我正在设置部署,我需要确保我的服务器已配置,以便我可以 运行 asp.net 核心应用程序。
基本上,我正在寻找注册表项或其他方式来告诉我是否应该 运行 安装程序设置。 (类似于我们判断是否安装了旧版本框架的方式,比如
https://support.microsoft.com/en-us/kb/318785
适用于早期版本)
如果您被允许引入约束,一种选择是只允许 "Self-contained applications",因为它们不需要任何额外的安装。这也使得 'what version is installed' 之类的问题消失了。
如果您需要支持 'portable apps',您可以简单地执行以下命令来检查 dotnet.exe 是否可用:
where dotnet
然后您可以查看版本:
dotnet --version
一旦出现问题,您还可以检查 .NET Core 的版本。
你可以看看
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall{ab4f6e29-67a1-47d9-b2ab-43348a9bbae4}
并确保 "Microsoft .NET Core 1.0.0 - Windows Server Hosting" 在那里
也可以双击DotNetCore.1.0.1-WindowsHosting.exe
如果 .NET Core Windows 服务器托管捆绑包已经安装,则开头 window 将具有:
- 修改设置标签
- 修复和卸载按钮
修复和卸载按钮以及修改安装标签。
您可以使用 powershell 检查托管模块是否已在 IIS 中注册
在本地 powershell 会话中
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"
}
如果您想在远程会话中执行,请将前两行替换为
Invoke-Command -Session $Session {Import-module WebAdministration}
$vm_dotnet_core_hosting_module = Invoke-Command -Session $Session {Get-WebGlobalModule | where-object { $_.name.ToLower() -eq "aspnetcoremodule" }}
您可以在 HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Updates\.NET Core
路径下搜索 Microsoft .NET Core 1.1.1 - Windows Server Hosting
注册表项,如下面的屏幕截图。
您也可以使用 PowerShell 来确定密钥是否存在。
$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"
}
您可以从 How to determine ASP.NET Core installation on a Windows Server by PowerShell 下载示例。
请注意,命令需要以管理员身份在 powershell 中 运行。
使用IISAdministration powershell module可以列出所有模块如下:
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")}}
所以测试可以是
$coreModule =
(Get-IISConfigSection -SectionPath "system.webServer/globalModules" `
| Get-IISConfigCollection).GetCollection() `
| where {$_.GetAttributeValue("name") -eq "AspNetCoreModuleV2" }
if (-not $coreModule)
{
throw 'AspNetCoreModuleV2 is not installed'
}
请注意,在撰写本文时,AspNetCoreModule
和 AspNetcoreModuleV2
均单独列出。将来可能会出现其他版本。
如果你安装了.NET Core CLI,你可以试试:
dotnet --list-runtimes
这将打印如下内容:
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]