32/64 位的 MSBuild 和 $(ProgramFiles) 问题 [英] MSBuild and $(ProgramFiles) issue with 32/64 bits
问题描述
我编写了一个调用 SubWCRev.exe
的自定义 MSBuild 任务,一个可执行文件(通常)驻留在 C:Program FilesTortoiseSVNin
中,无论是 32或 64 位,因为 TortoiseSVN 提供这两个版本.
I wrote a custom MSBuild task which calls SubWCRev.exe
, an executable which (typically) resides in C:Program FilesTortoiseSVNin
, whether it's 32 or 64 bits, since TortoiseSVN provides both versions.
问题是,Visual Studio 2010 只有 32 位版本.因此,当我使用 64 位机器的同事尝试使用我闪亮的新任务进行构建时,$(ProgramFiles)
解析为 C:Program Files(x86)
并且它爆炸说找不到 SubWCRev.exe
.因为他们有 64 位版本的 TortoiseSVN,它位于 C:Program Files
!
The problem is, Visual Studio 2010 only has a 32 bit version. So when my colleagues with a 64 bit box try to build using my shiny new task, $(ProgramFiles)
resolves to C:Program Files(x86)
and it explodes saying that SubWCRev.exe
cannot be found. Because they have the 64 bit version of TortoiseSVN, which lives in C:Program Files
!
是否有比在我的 msbuild 脚本中硬编码 C:Program Files
或让每个人都使用 32 位版本的 TortoiseSVN 更好的解决方案?(其实是C#项目,MSBuild代码稍微修改了一下)
Is there a better solution than hardcoding C:Program Files
in my msbuild script, or having everyone use the 32 bit version of TortoiseSVN? (Actually it's a C# project, I tinkered with the MSBuild code a bit)
推荐答案
看看这个:
<Project ToolsVersion="4.0" DefaultTargets="PrintValues" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PrintValues">
<PropertyGroup>
<MyProgramFiles>$(ProgramW6432)</MyProgramFiles>
<MyProgramFiles Condition="$(MyProgramFiles) == ''">$(ProgramFiles)</MyProgramFiles>
</PropertyGroup>
<Message Text="MyProgramFiles: $(MyProgramFiles)"/>
</Target>
</Project>
这让 MyProgramFiles
解析为 32 位和 64 位 Windows 的C:Program Files"(ProgramW6432
环境变量在非 64 位版本的 Windows视窗).
This lets MyProgramFiles
resolve to "C:Program Files" for both 32 and 64 bit Windows (The ProgramW6432
environment variable is empty on non-64 bit versions of Windows).
这篇关于32/64 位的 MSBuild 和 $(ProgramFiles) 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!