visual-studio - 如何在批处理文件中找到最新的 Visual Studio 开发人员命令提示符?

标签 visual-studio batch-file command-prompt

我需要编写一个批处理文件来完成 Visual Studio 中的预构建步骤。作为其中的一部分,我需要调用 Visual Studio 开发人员命令提示符。

我知道对于 VS2015,开发人员命令提示位于 C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat

不幸的是,我们的构建服务器有不同版本的 VS。是否有一种简单的方法可以在批处理文件中找到所有(或大多数)Visual Studio 版本的最新 VSDevCmd.bat,以便预构建步骤适用于两种环境?

最佳答案

你应该使用 vswhere由 Microsoft Visual Studio 安装程序提供。您将 vswhere.exe 复制到已知位置。 wiki 上有关于 how to start the developer command prompt 的描述。 :

@if not defined _echo echo off
for /f "usebackq delims=" %%i in (`vswhere.exe -prerelease -latest -property installationPath`) do (
  if exist "%%i\Common7\Tools\vsdevcmd.bat" (
    %comspec% /k "%%i\Common7\Tools\vsdevcmd.bat" %*
    exit /b
  )
)

rem Instance or command prompt not found
exit /b 2

关于visual-studio - 如何在批处理文件中找到最新的 Visual Studio 开发人员命令提示符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46732926/

相关文章:

c# - 如何让 Visual Studio 2017 以交互方式调试此行?

c# - ASP.NET 中的日期时间选择器控件

windows - 有没有办法从 for 循环中的通配符中排除某些值/变量

c++ - 如何在运行时确定您的 C++ 应用程序何时附加了 visual studio 调试器?

git - 如何让 Visual Studio 自动获取传入的提交

python - 使用静音检测分割音频文件

batch-file - 变量名中的字符转义

windows - 将声音输出到音频设备

postgresql - 连接到命令提示符以在 PostgreSQL 查询中通过 GNupg 生成 key

command-line-arguments - 如何从命令行运行 pentaho 作业