Asp.net core 如何确定windows服务器上是否安装了asp.net core

Asp.net core 如何确定windows服务器上是否安装了asp.net core,asp.net-core,.net-core,Asp.net Core,.net Core,我正在设置各种windows服务器来托管asp.net核心应用程序,我需要能够确定它们是否安装了asp.net托管捆绑包 说: “在服务器上安装.NET核心Windows服务器托管捆绑包。 该捆绑包将安装.NET Core运行时、.NET Core库和 ASP.NET核心模块。该模块在 IIS和Kestrel服务器。“ 我正在设置部署,我需要确保我的服务器已配置,以便可以运行asp.net核心应用程序 基本上,我在寻找一个注册表项或其他方法来告诉我是否应该运行安装程序。(类似于我们判断是否安装了

我正在设置各种windows服务器来托管asp.net核心应用程序,我需要能够确定它们是否安装了asp.net托管捆绑包

说:

“在服务器上安装.NET核心Windows服务器托管捆绑包。 该捆绑包将安装.NET Core运行时、.NET Core库和 ASP.NET核心模块。该模块在 IIS和Kestrel服务器。“

我正在设置部署,我需要确保我的服务器已配置,以便可以运行asp.net核心应用程序

基本上,我在寻找一个注册表项或其他方法来告诉我是否应该运行安装程序。(类似于我们判断是否安装了较旧版本的框架的方式,如
https://support.microsoft.com/en-us/kb/318785

如果允许引入约束,一个选项是只允许“自包含应用程序”,因为它们不需要任何附加安装。这也使得诸如“安装了什么版本”之类的问题消失了

如果您需要支持“便携式应用程序”,只需执行以下操作即可检查dotnet.exe是否可用:

where dotnet

然后,您可以检查版本:

dotnet——版本

这还允许您在出现问题时检查.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服务器托管捆绑包,则打开的窗口将有:

  • 修改设置标签
  • 修复和卸载按钮
  • 修复和卸载按钮以及修改设置标签。

    您可以使用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\U LOCAL\U MACHINE\SOFTWARE\WOW6432Node\Microsoft\Update\.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"
    }
    

    您可以从下载示例。

    注意,这些命令需要作为管理员在powershell中运行

    使用“所有模块”可以如下所示:

    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]


    参考:

    这将仅检测到使用了特定的安装程序。。。当下一次更新可用时,它可能不再工作。没错,我假设它的工作原理与检测遗留.net版本的工作原理相同:您在注册表中寻找框架特定版本的特定键。我喜欢这个答案,但是在64位与32位powershell中的哪一个之间有困难?如何执行此命令?只有在不关心安装了哪个版本的情况下才可以执行此命令…此命令即使在安装模块后也不会显示该模块。对我来说,这是因为该模块实际上被称为
    AspNetCoreModuleV2
    。如果未安装该模块,“Get Item-ErrorAction Stop-Path$dotnetcoreUpdatePath”将出错,脚本将永远不会完成。脚本需要被try-catch包围才能工作。如果您愿意,我可以编辑答案,将其包括在内。或者,我们可以使用测试路径检查$DotNetCoreUpdatePath是否存在:$NotInstalled=$True$DotNetCoreUpdatePath=“Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Updates\.NET Core”if(测试路径$DotNetCoreUpdatePath){$DotNetCoreItems=Get Item-ErrorAction Stop-Path$DotNetCoreUpdatePath$NotInstalled=$True$DotNetCoreItems.GetSubKeyNames()|其中{$|-Match“Microsoft.NET Core.*Windows Server Hosting”}ForEach对象{$NotInstalled=$False Write Host”主机已安装$|(…)不适用于我最新版本的frameworkNice-不需要在注册表或powershell上乱搞。