vsdevshell
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseVsDevShell (Visual Studio Developer Shell)
VsDevShell(Visual Studio开发人员Shell)
Use this skill when you need to run Windows build tools that typically only work after a Visual Studio Developer Prompt / has been applied.
VsDevCmd.bat当你需要运行通常只有在打开Visual Studio开发人员提示符或执行后才能正常工作的Windows构建工具时,可以使用本技能。
VsDevCmd.batWhen to use
使用场景
Use this skill when you see errors like:
msbuild : The term 'msbuild' is not recognized...- /
cl.exe/link.exenot foundrc.exe - CMake/Ninja can’t find the MSVC toolchain
Start with , but the same approach applies to many VS toolchain commands.
msbuild当你遇到以下错误时,可使用本技能:
msbuild : 术语“msbuild”未被识别...- 找不到/
cl.exe/link.exerc.exe - CMake/Ninja 无法找到MSVC工具链
以为例,该方法同样适用于许多VS工具链命令。
msbuildCommon tools that often need VS dev env
通常需要VS开发环境的工具
If you need to run any of the following, enter the VS dev shell first so PATH/Windows SDK/VC tools variables are set correctly:
- Build / project tooling: ,
msbuild.exe,devenv.comnmake.exe - Build systems (sometimes VS-bundled): ,
cmake.exeninja.exe - Packaging & signing (Windows SDK): ,
signtool.exe,makeappx.exe,makepri.exeappcert.exe - Resources & manifests (Windows SDK): ,
rc.exe,mt.exemc.exe - IDL / interop: ,
midl.exe,tlibimp.exetlbexp.exe - Binary inspection & PDB/symbol utilities (varies by installed components): ,
dumpbin.exe,pdbcopy.exe,pdbstr.exe,symstore.exesymchk.exe - Driver/INF tooling (specialized; requires WDK components):
inf2cat.exe
If the user’s command references one of these tools (or a build script calls them indirectly), run the “enter dev env” step before running the command.
如果你需要运行以下任一工具,请先进入VS开发Shell,确保PATH/Windows SDK/VC工具变量配置正确:
- 构建/项目工具:、
msbuild.exe、devenv.comnmake.exe - 构建系统(部分为VS捆绑):、
cmake.exeninja.exe - 打包与签名(Windows SDK):、
signtool.exe、makeappx.exe、makepri.exeappcert.exe - 资源与清单(Windows SDK):、
rc.exe、mt.exemc.exe - IDL/互操作:、
midl.exe、tlibimp.exetlbexp.exe - 二进制检查与PDB/符号工具(取决于已安装组件):、
dumpbin.exe、pdbcopy.exe、pdbstr.exe、symstore.exesymchk.exe - 驱动程序/INF工具(专用工具,需WDK组件):
inf2cat.exe
如果用户的命令引用了上述任一工具(或构建脚本间接调用它们),请在运行命令前执行“进入开发环境”步骤。
Key idea
核心概念
Enter-VsDevShell- Run it in the same terminal/session where you will run .
msbuild - In VS Code tool runners, avoid starting a brand-new shell between “enter dev env” and “build”.
To restore the original environment (the values captured when you entered), use:
Exit-VsDevShell
Enter-VsDevShell- 请在你将要运行的同一个终端/会话中执行该命令。
msbuild - 在VS Code工具运行器中,避免在“进入开发环境”和“构建”步骤之间启动全新的Shell。
如需恢复到进入时的原始环境(保存的初始值),可使用:
Exit-VsDevShell
Important: one-time per PowerShell process
重要提示:每个PowerShell进程仅需执行一次
Treat as a one-time initialization step per PowerShell process:
Enter-VsDevShell- If you start a fresh /
pwshprocess (new terminal tab, new task invocation, new CI step, etc.) and you need VS build tools, you must callpowershell.exein that process.Enter-VsDevShell - If you reuse an existing PowerShell process where you already called , don’t call it again.
Enter-VsDevShell - If you really need to re-enter without leaving, use .
Enter-VsDevShell -Force - If you need a different dev environment (for example a different /
-Arch/-HostArch), use a new PowerShell process and call-WinSdkthere with the new parameters.Enter-VsDevShell
将视为每个PowerShell进程仅需执行一次的初始化步骤:
Enter-VsDevShell- 如果你启动了一个全新的/
pwsh进程(新终端标签、新任务调用、新CI步骤等),且需要使用VS构建工具,则必须在该进程中调用powershell.exe。Enter-VsDevShell - 如果你复用了一个已调用过的PowerShell进程,请不要再重复调用。
Enter-VsDevShell - 如果你确实需要在不退出的情况下重新进入,请使用。
Enter-VsDevShell -Force - 如果你需要一个不同的开发环境(例如不同的/
-Arch/-HostArch参数),请使用新的PowerShell进程,并在其中使用新参数调用-WinSdk。Enter-VsDevShell
Prerequisite
前提条件
This skill assumes the module is installed and available on .
VsDevShellPSModulePath- Verify availability:
Get-Module -ListAvailable VsDevShell
If it isn't present, install it from PowerShell Gallery for the current user:
Install-Module -Name VsDevShell -Repository PSGallery -Scope CurrentUser
Then import it:
Import-Module VsDevShell
Notes:
- On first install, PowerShell may prompt to install the NuGet provider and/or to trust .
PSGallery
本技能假设模块已安装且在中可用。
VsDevShellPSModulePath- 验证可用性:
Get-Module -ListAvailable VsDevShell
如果模块未安装,可从PowerShell Gallery为当前用户安装:
Install-Module -Name VsDevShell -Repository PSGallery -Scope CurrentUser
然后导入模块:
Import-Module VsDevShell
注意:
- 首次安装时,PowerShell可能会提示安装NuGet提供程序和/或信任。
PSGallery
Parameter mapping (intent → Enter-VsDevShell)
参数映射(意图 → Enter-VsDevShell)
- : target architecture you want to build for
-Arch- Build →
Win32-Arch x86 - Build →
x64-Arch x64 - Build →
ARM64-Arch arm64
- Build
- : architecture of the machine running the tools
-HostArch- Typical x64 Windows host →
-HostArch x64 - Typical x86 Windows host →
-HostArch x86 - Note: currently only /
x86are accepted forx64.-HostArch
- Typical x64 Windows host →
- : accepted for compatibility, but currently not used to build
-AppPlatformarguments.VsDevCmd.bat - : optional Windows SDK version string (only set when the user specifies a required SDK)
-WinSdk - ,
-NoExt: optional switches to reduce startup work/noise-NoLogo - : only set when targeting a specific Visual Studio installation
-VsInstallPath
- :你要构建的目标架构
-Arch- 构建→
Win32-Arch x86 - 构建→
x64-Arch x64 - 构建→
ARM64-Arch arm64
- 构建
- :运行工具的机器架构
-HostArch- 典型x64 Windows主机 →
-HostArch x64 - 典型x86 Windows主机 →
-HostArch x86 - 注意:目前仅接受
-HostArch/x86。x64
- 典型x64 Windows主机 →
- :为兼容而保留,但目前不会用于构建
-AppPlatform参数。VsDevCmd.bat - :可选的Windows SDK版本字符串(仅当用户指定所需SDK时设置)
-WinSdk - 、
-NoExt:可选开关,用于减少启动工作/输出信息-NoLogo - :仅当针对特定Visual Studio安装时设置
-VsInstallPath
Recommended workflow (msbuild)
推荐工作流(msbuild)
- Import and enter the environment (x64 host building x64):
- Run in the current PowerShell session:
Import-Module VsDevShellEnter-VsDevShell -Arch x64 -HostArch x64 -NoLogo
- Verify:
- Run:
msbuild -version
-
Build:
- Run your command (solution/project + configuration/platform as requested).
msbuild
- Run your
- 导入并进入环境(x64主机构建x64):
- 在当前PowerShell会话中运行:
Import-Module VsDevShellEnter-VsDevShell -Arch x64 -HostArch x64 -NoLogo
- 验证:
- 运行:
msbuild -version
-
构建:
- 运行你的命令(按要求指定解决方案/项目 + 配置/平台)。
msbuild
- 运行你的
VS Code / tool-runner tip
VS Code / 工具运行器提示
If your tool runner uses a fresh PowerShell process per command, run the “enter dev env” step and the build command in the same invocation, for example:
pwsh -NoProfile -Command "Import-Module VsDevShell; Enter-VsDevShell -Arch x64 -HostArch x64 -NoLogo; msbuild -version"
If your tool runner reuses a single long-lived terminal session, run once at the start of that session, then run as many build commands as you need in the same session.
Enter-VsDevShell如果你的工具运行器每个命令都使用全新的PowerShell进程,请将“进入开发环境”步骤和构建命令放在同一个调用中،例如:
pwsh -NoProfile -Command "Import-Module VsDevShell; Enter-VsDevShell -Arch x64 -HostArch x64 -NoLogo; msbuild -version"
如果你的工具运行器复用单个长期运行的终端会话,请在会话开始时运行一次,然后在同一个会话中运行任意数量的构建命令。
Enter-VsDevShellCross-compile examples
交叉编译示例
-
Build Win32 from an x64 machine:
Enter-VsDevShell -Arch x86 -HostArch x64
-
Build ARM64 from an x64 machine:
Enter-VsDevShell -Arch arm64 -HostArch x64
-
在x64机器上构建Win32:
Enter-VsDevShell -Arch x86 -HostArch x64
-
在x64机器上构建ARM64:
Enter-VsDevShell -Arch arm64 -HostArch x64
Inspect without applying
查看配置而不应用
If you want to see what would change without modifying your current process environment:
Get-VsDevEnv -Arch x64 -HostArch x64 | Format-Table -AutoSize
如果你想查看会发生哪些更改,而不修改当前进程环境:
Get-VsDevEnv -Arch x64 -HostArch x64 | Format-Table -AutoSize
Cmdlets and common workflows
Cmdlet与常见工作流
Enter / Leave
进入 / 退出
- Compute + apply VS dev environment:
Enter-VsDevShell -Arch x64 -HostArch x64
- Restore original values captured at enter time:
Exit-VsDevShell
- 计算并应用VS开发环境:
Enter-VsDevShell -Arch x64 -HostArch x64
- 恢复进入时保存的原始值:
Exit-VsDevShell
Export / Import .env
.env导出 / 导入 .env
文件
.envExport the computed delta to a standard file (UTF-8 no BOM):
.envExport-VsDevEnv -Arch x64 -HostArch x64 -Path .\vsdev.env -Mode Update
Apply a file in the current session:
.env- Pipeline form:
Import-VsDevEnv .\vsdev.env | Enter-VsDevShell
- Shortcut:
Enter-VsDevShell -EnvFilePath .\vsdev.env
Restore only the keys listed in the file (using the saved pre-enter snapshot):
Exit-VsDevShell -EnvFilePath .\vsdev.env
Fully piped chain (compute → export → import → apply):
powershell
Get-VsDevEnv -Arch x64 -HostArch x64 |
Export-VsDevEnv -Path .\vsdev.env -Mode Update -PassThru |
Import-VsDevEnv |
Enter-VsDevShellNotes:
- This writes the computed values (including ) and will typically override whatever values your target process already has.
PATH - Loading a dotenv file varies by tool/shell. For example, in you often need
bashto export the variables to child processes.set -a; source ./vsdev.env; set +a
将计算出的环境变量差异导出为标准文件(UTF-8无BOM):
.envExport-VsDevEnv -Arch x64 -HostArch x64 -Path .\vsdev.env -Mode Update
在当前会话中应用文件:
.env- 管道形式:
Import-VsDevEnv .\vsdev.env | Enter-VsDevShell
- 快捷方式:
Enter-VsDevShell -EnvFilePath .\vsdev.env
仅恢复文件中列出的键(使用保存的进入前快照):
Exit-VsDevShell -EnvFilePath .\vsdev.env
完整管道链(计算 → 导出 → 导入 → 应用):
powershell
Get-VsDevEnv -Arch x64 -HostArch x64 |
Export-VsDevEnv -Path .\vsdev.env -Mode Update -PassThru |
Import-VsDevEnv |
Enter-VsDevShell注意:
- 该操作会写入计算后的值(包括),通常会覆盖目标进程已有的值。
PATH - 加载dotenv文件的方式因工具/Shell而异。例如,在中,你通常需要执行
bash才能将变量导出到子进程。set -a; source ./vsdev.env; set +a
GitHub Actions (GITHUB_ENV
)
GITHUB_ENVGitHub Actions(GITHUB_ENV
)
GITHUB_ENVIn GitHub Actions, is a standard env file shared across steps.
Update it so later steps inherit the VS dev environment:
$env:GITHUB_ENVExport-VsDevEnv -Arch x64 -HostArch x64 -Path $env:GITHUB_ENV -Mode Update
If is available and you want PATH handled there, use:
$env:GITHUB_PATHExport-VsDevEnv -Arch x64 -HostArch x64 -Path $env:GITHUB_ENV -Mode Update -PathMode GitHubPath
Apply it in the current step/session (optional):
Enter-VsDevShell -EnvFilePath $env:GITHUB_ENV
在GitHub Actions中,是跨步骤共享的标准环境文件。更新它以便后续步骤继承VS开发环境:
$env:GITHUB_ENVExport-VsDevEnv -Arch x64 -HostArch x64 -Path $env:GITHUB_ENV -Mode Update
如果可用,且你希望在其中处理PATH,请使用:
$env:GITHUB_PATHExport-VsDevEnv -Arch x64 -HostArch x64 -Path $env:GITHUB_ENV -Mode Update -PathMode GitHubPath
在当前步骤/会话中应用(可选):
Enter-VsDevShell -EnvFilePath $env:GITHUB_ENV
Notes
注意事项
- Windows only (relies on and Visual Studio's
%COMSPEC%).VsDevCmd.bat - If still isn’t available after enabling the environment, the installed Visual Studio workload may be missing MSBuild/VC tools.
msbuild - is currently accepted but not used to build
AppPlatformarguments.VsDevCmd.bat
- 仅支持Windows系统(依赖和Visual Studio的
%COMSPEC%)。VsDevCmd.bat - 如果启用环境后仍不可用,可能是已安装的Visual Studio工作负载缺少MSBuild/VC工具。
msbuild - 目前仅为兼容而保留,不会用于构建
AppPlatform参数。VsDevCmd.bat