本文介绍了MSBuild和$(ProgramFiles)问题出现在32/64位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我编写了一个自定义MSBuild任务,该任务调用SubWCRev.exe,这是一个可执行文件(通常为32位或64位),通常位于C:\Program Files\TortoiseSVN\bin中,因为TortoiseSVN提供了这两个版本.

I wrote a custom MSBuild task which calls SubWCRev.exe, an executable which (typically) resides in C:\Program Files\TortoiseSVN\bin, 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).

这篇关于MSBuild和$(ProgramFiles)问题出现在32/64位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:17