如何获取ASP.NET Core 6托管捆绑包与URL重写的Windows功能名称?
ASP.NET Core 6 托管捆绑包安装说明
ASP.NET Core 6托管捆绑包不属于Windows内置功能,因此无法通过Get-WindowsFeature或DISM命令查询到对应的功能名称,需要单独下载官方安装程序进行部署。
PowerShell自动化安装步骤:
- 确保已安装IIS基础组件(若未安装):
Install-WindowsFeature Web-Server, Web-WebServer, Web-Common-Http, Web-Default-Doc, Web-Dir-Browsing, Web-Http-Errors, Web-Static-Content, Web-Health, Web-Http-Logging, Web-Performance, Web-Stat-Compression, Web-Dyn-Compression, Web-Security, Web-Filtering, Web-App-Dev, Web-Net-Ext45, Web-Asp-Net45, Web-ISAPI-Ext, Web-ISAPI-Filter -IncludeManagementTools - 下载并静默安装托管捆绑包:
# 定义安装包下载路径 $installerPath = "$env:TEMP\AspNetCoreHostingBundle.exe" # 下载官方安装程序 Invoke-WebRequest -Uri "https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-aspnetcore-6.0.26-windows-hosting-bundle-installer" -OutFile $installerPath # 静默安装(/quiet 无交互,/norestart 不自动重启) Start-Process -FilePath $installerPath -ArgumentList "/quiet /norestart" -Wait # 清理临时文件 Remove-Item $installerPath -Force
URL重写模块安装说明
URL重写模块是IIS的扩展组件,同样不属于Windows核心功能,无法通过Get-WindowsFeature查询,需单独安装。
PowerShell自动化安装步骤:
# 定义MSI下载路径 $msiPath = "$env:TEMP\rewrite_amd64_en-US.msi" # 下载官方MSI安装包 Invoke-WebRequest -Uri "https://download.microsoft.com/download/1/2/8/128E2E22-C1B9-44A4-BE2A-5859ED1D4592/rewrite_amd64_en-US.msi" -OutFile $msiPath # 静默安装 Start-Process msiexec.exe -ArgumentList "/i `"$msiPath`" /quiet /norestart" -Wait # 清理临时文件 Remove-Item $msiPath -Force
最优PowerShell部署脚本示例
整合上述步骤并增加安装前检查逻辑,避免重复安装:
# 检查IIS是否已安装 $iisInstalled = Get-WindowsFeature Web-Server | Select-Object -ExpandProperty Installed if (-not $iisInstalled) { Write-Host "正在安装IIS基础组件..." Install-WindowsFeature Web-Server, Web-WebServer, Web-Common-Http, Web-Default-Doc, Web-Dir-Browsing, Web-Http-Errors, Web-Static-Content, Web-Health, Web-Http-Logging, Web-Performance, Web-Stat-Compression, Web-Dyn-Compression, Web-Security, Web-Filtering, Web-App-Dev, Web-Net-Ext45, Web-Asp-Net45, Web-ISAPI-Ext, Web-ISAPI-Filter -IncludeManagementTools } # 检查ASP.NET Core 6托管捆绑包是否已安装 $hostingBundleInstalled = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\ASP.NET Core\6.0.*" -ErrorAction SilentlyContinue if (-not $hostingBundleInstalled) { Write-Host "正在安装ASP.NET Core 6托管捆绑包..." $installerPath = "$env:TEMP\AspNetCoreHostingBundle.exe" Invoke-WebRequest -Uri "https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-aspnetcore-6.0.26-windows-hosting-bundle-installer" -OutFile $installerPath Start-Process -FilePath $installerPath -ArgumentList "/quiet /norestart" -Wait Remove-Item $installerPath -Force } # 检查URL重写模块是否已安装 $rewriteInstalled = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\IIS Extensions\URL Rewrite\2.0" -ErrorAction SilentlyContinue if (-not $rewriteInstalled) { Write-Host "正在安装URL重写模块..." $msiPath = "$env:TEMP\rewrite_amd64_en-US.msi" Invoke-WebRequest -Uri "https://download.microsoft.com/download/1/2/8/128E2E22-C1B9-44A4-BE2A-5859ED1D4592/rewrite_amd64_en-US.msi" -OutFile $msiPath Start-Process msiexec.exe -ArgumentList "/i `"$msiPath`" /quiet /norestart" -Wait Remove-Item $msiPath -Force } Write-Host "所有组件安装完成!"
内容的提问来源于stack exchange,提问作者user18573892
相关产品推荐
相关产品推荐

