如何列出IIS服务器上网站使用的.NET (Core)版本(不含.NET Framework)?
如何列出IIS中所有网站正在使用的.NET Core版本
以下是几种实用的方法,可快速定位所有IIS站点当前使用的.NET Core版本,帮助你清理过时的框架:
方法1:通过IIS管理器查看站点配置版本
- 打开IIS管理器,展开左侧的站点列表
- 选中目标站点,在右侧「功能视图」中找到ASP.NET Core模块(若未显示,需确认服务器已安装ASP.NET Core托管捆绑包)
- 在模块详情界面,直接查看「.NET Core版本」字段,即可获取该站点配置的共享框架版本
方法2:通过进程查看实时运行版本
- 打开任务管理器,切换到「详细信息」标签页
- 找到对应站点的
dotnet.exe进程(若为自托管部署,可能是站点专属的可执行文件) - 右键进程选择「打开文件所在位置」,查看该
dotnet.exe的属性版本;或用PowerShell命令查询(替换<进程ID>为实际ID):Get-Process -Id <进程ID> | Select-Object Path, @{Name='Version'; Expression={(Get-Item $_.Path).VersionInfo.ProductVersion}} - 注意:多个站点共享同一
dotnet.exe进程时,说明它们使用相同的.NET Core版本
方法3:检查站点部署文件的版本信息
- 查看站点根目录下的
web.config文件,找到<aspNetCore>节点:- 若
processPath为dotnet,则需查看站点根目录的runtimeconfig.json文件,其中runtimeOptions.framework.version字段明确标注了使用的.NET Core版本 - 也可查看发布目录下的
*.deps.json文件,搜索Microsoft.NETCore.App或Microsoft.AspNetCore.App的版本号,获取依赖的框架版本
- 若
- 若站点为自托管(
processPath是自定义exe),直接查看该exe文件的属性版本即可
方法4:PowerShell批量遍历所有站点
使用脚本批量查询所有IIS站点的.NET Core版本,无需逐个手动检查:
Import-Module WebAdministration Get-ChildItem IIS:\Sites | ForEach-Object { $siteName = $_.Name $webConfigPath = Join-Path $_.PhysicalPath "web.config" if (-not (Test-Path $webConfigPath)) { Write-Output "[$siteName] 未找到web.config文件" return } $xml = [xml](Get-Content $webConfigPath) $aspNetCoreNode = $xml.configuration.'system.webServer'.aspNetCore if (-not $aspNetCoreNode) { Write-Output "[$siteName] 未配置ASP.NET Core模块" return } if ($aspNetCoreNode.processPath -eq 'dotnet') { $dllName = $aspNetCoreNode.arguments.Split(' ')[0] $runtimeConfigPath = Join-Path $_.PhysicalPath "$($dllName.Split('.')[0]).runtimeconfig.json" if (Test-Path $runtimeConfigPath) { $runtimeConfig = Get-Content $runtimeConfigPath | ConvertFrom-Json $frameworkVersion = $runtimeConfig.runtimeOptions.framework.version Write-Output "[$siteName] 使用的.NET Core版本: $frameworkVersion" } else { Write-Output "[$siteName] 未找到runtimeconfig.json文件" } } else { $exeVersion = (Get-Item $aspNetCoreNode.processPath).VersionInfo.ProductVersion Write-Output "[$siteName] 自托管进程版本: $exeVersion" } }
内容的提问来源于stack exchange,提问作者Bernard Vander Beken
相关产品推荐
相关产品推荐

