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

如何将Developer PowerShell重新指向Visual Studio 2022的devenv.exe

解决Visual Studio 2022 Developer PowerShell启动报错问题

问题重现步骤

  • 卸载Visual Studio 2019
  • 安装Visual Studio 2022
  • 打开Visual Studio 2022
  • 右键点击任意项目
  • 在菜单中选择「Open in Terminal」

此时Developer PowerShell启动后会抛出如下错误:

vs : The term 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.exe' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At C:\Users\jdoe\OneDrive\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:340 char:2

  • vs "C:\EDW\My Project\My Project.sl ...
    
  • ~~
    
    • CategoryInfo : ObjectNotFound: (C:\Program File...\IDE\devenv.exe:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

** Visual Studio 2022 Developer PowerShell v17.4.4
** Copyright (c) 2022 Microsoft Corporation


解决方案

报错根源是你的PowerShell配置文件(Microsoft.PowerShell_profile.ps1)里的vs别名/函数指向了已卸载的VS2019的devenv.exe路径,VS2022终端启动时会加载这个配置文件,导致路径找不到。

按以下步骤修复:

  1. 打开PowerShell,输入命令打开配置文件:
    notepad $PROFILE
    
  2. 在文件中定位到第340行附近的vs相关代码(比如Set-Alias vs "旧的VS2019路径"这类内容)
  3. 将路径修改为VS2022的devenv.exe实际路径,示例:
    # 企业版示例
    Set-Alias vs "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\devenv.exe"
    # 社区版示例
    Set-Alias vs "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\devenv.exe"
    
    注意:根据你安装的VS2022版本(社区/专业/企业)和自定义安装位置调整路径。
  4. 保存配置文件,关闭并重新启动Developer PowerShell,报错即可解决。

如果找不到vs的定义,直接删除相关行也可以,VS2022的终端环境会自动配置正确的devenv路径。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 07:20:42