使用32位"程序文件"在MSBuild的目录文件、目录、程序、QUOT

由网友(ωǒ不特別卻是唯1╮)分享简介:在64位版本的Windows中,32位软件将安装在C:\ Program Files文件(x86)的。这意味着你不能使用$(PROGRAMFILES)来获得路径(32位)的软件。所以,我需要一个$(ProgramFiles32)克服这在我的MSBuild项目。我并不想改变这取决于它是运行在OS项目。In 64 bit...

在64位版本的Windows中,32位软件将安装在C: Program Files文件(x86)的。这意味着你不能使用$(PROGRAMFILES)来获得路径(32位)的软件。所以,我需要一个$(ProgramFiles32)克服这在我的MSBuild项目。我并不想改变这取决于它是运行在OS项目。

In 64 bit versions of windows, 32 bit software is installed in "c:program files (x86)". This means you cannot use $(programfiles) to get the path to (32 bit) software. So I need a $(ProgramFiles32) to overcome this in my MSBuild project. I don't want to change the project depending on the os it is running on.

我有我将发布一个解决方案,但也许有一个更简单/更好的办法。

I have a solution that I will post, but maybe there is a easier/better way.

推荐答案

在MSBuild的4.0+,有一个 $(MSBuildProgramFiles32)属性它,你可以放心地直接使用(特别是如果你ppared把$ P $一个 ToolsVersion =4.0在文件的顶部,以保证它的将是提供快速失败如果它不是)。

In MSBuild 4.0+, there's a $(MSBuildProgramFiles32) property for it, which you can confidently employ directly (especially if you're prepared to put a ToolsVersion="4.0" at the top of the file to guarantee it's going to be available and Fail Fast if it's not).

如果你不和需要的东西,可以做正确的事情,即使在MSBuild的2.0或更高版本的环境中执行(即回VS 2005环境),完整的解决方案是:

If you're not and need something that can Do The Right Thing even when executed in an MSBuild 2.0 or later environment (i.e., back to VS 2005 environments), the complete solution is:

<PropertyGroup>
    <!--MSBuild 4.0 property-->
    <ProgramFiles32>$(MSBuildProgramFiles32)</ProgramFiles32> 
    <!--Use OS env var as a fallback:- 32 bit MSBuild 2.0/3.5 on x64 will use this-->
    <ProgramFiles32 Condition=" '' == '$(ProgramFiles32)'">$(ProgramFiles%28x86%29)</ProgramFiles32>

    <!-- Handle MSBuild 2.0/3.5 running in 64 bit mode - neither of the above env vars are available. http://stackoverflow.com/questions/336633
       NB this trick (Adding a literal " (x86)" to the 64 bit Program Files path) may or may not work on all versions/locales of Windows -->
    <ProgramFiles32 Condition ="'$(ProgramFiles32)'=='' AND 'AMD64' == '$(PROCESSOR_ARCHITECTURE)'">$(ProgramFiles) (x86)</ProgramFiles32>

    <!--Catch-all - handles .NET 2.0/3.5 non-AMD64 and .NET 2.0 on x86 -->
    <ProgramFiles32 Condition=" '' == '$(ProgramFiles32)' ">$(ProgramFiles)</ProgramFiles32>
</PropertyGroup>

不幸的是渐进增强 /的在的MSBuild保留属性名称 MSBuildProgramFiles32 通过一根&LT;的PropertyGroup&GT; &LT; CreateProperty&GT; 被拒绝的MSBuild 4.0+,因此无法进行更为简洁并且还支持.NET 2.0。

Unfortunately Progressive enhancement / polyfill overriding of the MSBuild reserved property name MSBuildProgramFiles32 via either a <PropertyGroup> or <CreateProperty> is rejected by MSBuild 4.0+ so it can't be made tidier and still support .NET 2.0.

阅读全文

相关推荐

最新文章