You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Core 3.1即将弃用,如何定位环境中运行该版本的进程?

定位依赖.NET Core 3.1的遗漏程序方案

针对你的需求,以下是几种在Windows服务器(PowerShell 5.x环境)上定位依赖.NET Core 3.1程序的可行方案,覆盖静态扫描、运行时检查及IIS场景:

一、静态扫描指定路径的依赖配置文件

.NET Core应用的依赖信息会存储在特定配置文件中,可通过扫描这些文件快速定位目标程序:

1. 扫描.deps.json文件

该文件记录了应用的所有依赖包版本,可筛选出引用Microsoft.NETCore.App 3.1.x的条目:

$targetPaths = @("C:\path1", "C:\Deep\path2", "C:\Place\Where\Things\Are")
foreach ($path in $targetPaths) {
    Get-ChildItem -Path $path -Recurse -Filter *.deps.json -File | ForEach-Object {
        $content = Get-Content $_.FullName -Raw
        if ($content -match '"Microsoft.NETCore.App":\s*{\s*"version":\s*"3\.1\.\d+"') {
            Write-Host "发现依赖.NET Core 3.1的应用: $($_.DirectoryName)"
        }
    }
}

2. 扫描.runtimeconfig.json文件

该文件明确指定应用的目标.NET Core runtime版本,直接检查版本字段:

foreach ($path in $targetPaths) {
    Get-ChildItem -Path $path -Recurse -Filter *.runtimeconfig.json -File | ForEach-Object {
        try {
            $config = Get-Content $_.FullName -Raw | ConvertFrom-Json
            if ($config.runtimeOptions.framework.version -like "3.1.*") {
                Write-Host "目标版本为.NET Core 3.1的应用: $($_.DirectoryName)"
            }
        } catch {
            Write-Warning "解析配置文件失败: $($_.FullName)"
        }
    }
}

二、检查运行中的进程依赖

对于正在运行的程序,可通过进程模块分析或Sysinternals工具定位依赖3.1的实例:

1. PowerShell进程模块扫描

直接检查进程加载的coreclr.dll版本,确认是否为3.1系列:

Get-Process | ForEach-Object {
    try {
        $coreclrModules = $_.Modules | Where-Object { $_.FileName -match "coreclr\.dll$" }
        foreach ($mod in $coreclrModules) {
            $fileVersion = (Get-Item $mod.FileName -ErrorAction Stop).VersionInfo.FileVersion
            if ($fileVersion -like "3.1.*") {
                Write-Host "进程 $($_.Name) (PID: $($_.Id)) 加载.NET Core 3.1 runtime: $($mod.FileName)"
            }
        }
    } catch {
        # 跳过无权限访问的系统进程
        continue
    }
}

2. 使用Sysinternals Sigcheck工具

若允许部署Sysinternals组件,sigcheck.exe可批量扫描文件的依赖模块:

# 先将sigcheck.exe下载到临时路径(如C:\Temp)
$sigcheckPath = "C:\Temp\sigcheck.exe"
foreach ($path in $targetPaths) {
    & $sigcheckPath -m -q $path | Where-Object { $_ -match "coreclr\.dll.*3\.1\.\d+" }
}

三、IIS场景专项检查

针对使用NoManagedCode应用池的IIS站点,需结合物理路径扫描与进程检查:

  • 对所有IIS站点的物理路径执行第一部分的静态扫描,排查.deps.json和.runtimeconfig.json文件。
  • 检查IIS工作进程(w3wp.exe)的模块加载情况,执行第二部分的进程扫描逻辑,确认是否加载3.1版本的coreclr.dll。
  • 查看站点根目录的web.config,检查aspNetCore节点的配置,确认是否指向.NET Core 3.1的运行时路径。

四、移除前验证方案

在正式卸载.NET Core 3.1前,可通过以下方式验证遗漏情况:

  1. 临时重命名.NET Core 3.1的安装目录(如C:\Program Files\dotnet\shared\Microsoft.NETCore.App\3.1.xx)。
  2. 遍历指定路径下的所有EXE文件,逐一启动测试是否出现运行时错误。
  3. 重启所有IIS应用池,检查站点访问状态,同时监控Windows事件日志(应用程序日志)中的.NET相关报错。

内容的提问来源于stack exchange,提问作者jcolebrand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 02:41:26