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

移除PowerShell 7后VS2022调用其路径致MSB3073构建错误

解决VS2022卸载PowerShell7后构建触发MSB3073错误的问题

问题根源

卸载PowerShell 7后,VS2022未自动更新默认Shell配置,仍尝试调用已移除的C:\Program Files\PowerShell\7\pwsh.exe,导致项目PostBuild事件执行时找不到路径,触发MSB3073构建失败错误。

解决步骤

1. 重置VS2022默认Shell

  • 打开VS2022,点击顶部菜单栏工具 → 选项
  • 左侧导航栏展开环境 → 终端
  • 右侧"默认Shell"下拉菜单选择Command Prompt或系统自带的Windows PowerShell(路径为C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe),点击确定

2. 修正项目PostBuild事件(若存在硬编码路径)

  • 右键目标项目 → 属性
  • 展开生成事件 → 后期生成事件
  • 将命令中的"C:\Program Files\PowerShell\7\pwsh.exe"替换为系统自带PowerShell路径:"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe"
  • 点击应用 → 确定

3. 清理并重新构建

  • 点击顶部菜单栏生成 → 清理解决方案
  • 执行生成解决方案验证构建状态

错误日志参考

2>Target PostBuildEvent:
2>  The system cannot find the path specified.
2>  C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: The command "setlocal
2>  C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: "C:\Program Files\PowerShell\7\pwsh.exe" -noprofile -executionpolicy Bypass -file C:/prj-external-libs/vcpkg/scripts/buildsystems/msbuild/applocal.ps1 -targetBinary C:/8/_tmp/cpp/build/src/Debug/proj.exe -installedDir C:/prj-external-libs/vcpkg/installed/x64-windows/debug/bin -OutVariable out
2>  C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd
2>  C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: :cmEnd
2>  C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
2>  C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: :cmErrorLevel
2>  C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: exit /b %1
2>  C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: :cmDone
2>  C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd
2>  C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(155,5): error MSB3073: :VCEnd" exited with code 3.
2>Done building target "PostBuildEvent" in project "proj.vcxproj" -- FAILED.
2>
2>Done building project "proj.vcxproj" -- FAILED.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 22:10:10