【问题标题】:Cannot determine the location of the VS Common Tools folder无法确定 VS Common Tools 文件夹的位置
【发布时间】:2013-07-05 23:35:29
【问题描述】:

我有一个调用MSBuild 并构建三个Visual Studio 解决方案的批处理文件:

call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"

MSBuild solution0.sln  /property:Configuration=Release
MSBuild solution1.sln  /property:Configuration=Release  
MSBuild solution2.sln  /property:Configuration=Release

这很好用。但是,我想提示用户选择要构建的程序版本。根据用户输入,我们构建了一组特定的解决方案。

我的问题是,如果我在调用vcvarsall 之后修改PATH 变量,我将无法再调用MSBuild。

call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
set /P version="Enter the version number [1] or [2]:"

IF %version% == 1 (
    set PATH="%PATH%;%PATH_TO_VERSION1_LIBS%"
    MSBuild solution0_v1.sln  /property:Configuration=Release
    MSBuild solution1_v1.sln  /property:Configuration=Release   
    MSBuild solution2_v1.sln  /property:Configuration=Release
)

IF %version% == 2 (
    set PATH="%PATH%;%PATH_TO_VERSION2_LIBS%"
    MSBuild solution0_v2.sln  /property:Configuration=Release
    MSBuild solution1_v2.sln  /property:Configuration=Release   
    MSBuild solution2_v2.sln  /property:Configuration=Release
)

我收到以下错误:

Setting environment for using Microsoft Visual Studio 2010 x86 tools.
ERROR: Cannot determine the location of the VS Common Tools folder.

这很令人费解,因为定义了环境变量VS100COMNTOOLS。

【问题讨论】:

  • 去掉 PATH 赋值中的双引号。
  • @HansPassant 我添加了双引号,因为我使用的是 64 位机器。带有C:\Program Files (x86) 等特殊字符的目录会破坏批处理命令。
  • 它不会破坏 PATH 环境变量,嵌入空格很好。这 ;分号使其明确。您尝试过还是只是假设它不起作用?
  • 通过特殊字符,我指的是括号。在这里查看答案:stackoverflow.com/a/2771431/1538531

标签: visual-studio-2010 windows-7 batch-file msbuild


【解决方案1】:

这可能是解析错误,试试:

IF "%version%"=="1" set "PATH=%PATH%;%PATH_TO_VERSION1_LIBS%"
IF "%version%"=="1" (
    MSBuild solution0_v1.sln  /property:Configuration=Release
    MSBuild solution1_v1.sln  /property:Configuration=Release   
    MSBuild solution2_v1.sln  /property:Configuration=Release
)

IF "%version%"=="2" set "PATH=%PATH%;%PATH_TO_VERSION2_LIBS%"
IF "%version%"=="2" (
    MSBuild solution0_v2.sln  /property:Configuration=Release
    MSBuild solution1_v2.sln  /property:Configuration=Release   
    MSBuild solution2_v2.sln  /property:Configuration=Release
)

【讨论】:

  • 您说得对,先生!对不起,我花了一段时间才回复你。我不明白您的回答将如何解决问题。 set 命令周围的括号似乎导致了解析错误。
  • 是的,你是对的。在用括号括起来的代码块内,您无权访问 %variables% ,除非您使用 delayed expansion 。 并且延迟扩展在MSBuild 的批处理脚本外部不起作用。
猜你喜欢
  • 2015-10-19
  • 1970-01-01
  • 2018-12-28
  • 1970-01-01
  • 2022-02-05
  • 2016-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多