msbuild - 在msbuild中使用32位 "Program Files"目录

标签 msbuild x86 64-bit x86-64 program-files

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

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

最佳答案

在 MSBuild 4.0+ 中,有 a $(MSBuildProgramFiles32) property为此,您可以放心地直接使用它(特别是如果您准备在文件顶部放置 ToolsVersion="4.0" 以保证它可用,如果不可用则放置 Fail Fast )。

如果您不是并且需要即使在 MSBuild 2.0 或更高版本环境(即回到 VS 2005 环境)中执行时也能做正确的事情,完整的解决方案是:

<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>

不幸的是Progressive enhancement/polyfill覆盖 MSBuild reserved property姓名MSBuildProgramFiles32通过 <PropertyGroup><CreateProperty>被 MSBuild 4.0+ 拒绝,因此无法使其更整洁并仍然支持 .NET 2.0。

关于msbuild - 在msbuild中使用32位 "Program Files"目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/346175/

相关文章:

git - 从 MSBuild 获取 Git Long Hash

x86 - 强制 L1 缓存未命中

c - CMP+JE 是否比单个 MUL 消耗更多的时钟周期?

curl - Ubuntu 64bit 11.04 服务器和 curl 安装失败

docker - dotnetcoresdk 容器中的 "dotnet publish"命令生成没有详细信息的 EXE

c# - MSBuild 15 - 命名空间中不存在类型或命名空间 'Fakes'

delphi - 如何为 Delphi 项目执行 MSBUILD 的 'dry run'?

assembly - 镜像 Byte/X86 嵌入式程序集(在 Visual Studio 2010 中)

64-bit - 安装 python-igraph 0.7.1-4 会引发错误 "10038, ' 尝试对非套接字的内容进行操作'

windows - MSI 安装程序,64 位操作系统,写入\windows\system32\inetsrv 文件夹