使用 32 位“程序文件"msbuild 中的目录 [英] Use 32bit "Program Files" directory in msbuild

查看:30
本文介绍了使用 32 位“程序文件"msbuild 中的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 64 位版本的 windows 中,32 位软件安装在c:program files (x86)"中.这意味着您不能使用 $(programfiles) 来获取(32 位)软件的路径.所以我需要一个 $(ProgramFiles32) 在我的 MSBuild 项目中克服这个问题.我不想根据运行的操作系统更改项目.

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) 属性,您可以自信地直接使用它(特别是如果您准备放置一个 ToolsVersion="4.0"code> 在文件的顶部以保证它可用并且 Fail Fast 如果不是).

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>

不幸的是渐进增强/polyfill 覆盖了 MSBuild 保留属性 名称 MSBuildProgramFiles32 通过 > 被 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.

这篇关于使用 32 位“程序文件"msbuild 中的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆