为何Launch-VsDevShell.ps1会修改工作目录?如何避免?
解决Launch-VsDevShell.ps1执行后更改工作目录的问题
直接给你解决办法:在执行Launch-VsDevShell.ps1时添加-SkipAutomaticLocation参数,就能只配置MSVC的环境变量,不会自动切换到默认的C:\Users\USERNAME\source\repos目录。
具体操作方式:
直接在命令行执行:
替换路径为你实际的VS安装路径(根据VS版本、版本类型调整,比如2019、Enterprise版路径会有差异):powershell -ExecutionPolicy Bypass -Command "& 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1' -SkipAutomaticLocation"在PowerShell脚本中调用:
把路径改成你的VS对应路径就行:# 替换为你的Launch-VsDevShell.ps1实际路径 $vsDevShellScript = "C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1" & $vsDevShellScript -SkipAutomaticLocation额外需求:指定编译架构:
如果需要针对x64、x86等特定架构配置环境,可搭配-Arch参数:& $vsDevShellScript -SkipAutomaticLocation -Arch x64
内容的提问来源于stack exchange,提问作者Maxime Charrière
相关产品推荐
相关产品推荐

