MSBuild and $(ProgramFiles) issue with 32/64 bits

筅森魡賤 提交于 2019-12-03 07:04:07

Take a look it this:

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

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

Use MSBuildExtensionsPath property instead of hardcoding the path.

Per MSDN:

The MSBuild subfolder under the \Program Files\ or \Program Files (x86) folder. This path always points to the Program Files of the same bitness as the window you are currently running in. For example, for a 32-bit window on a 64-bit machine, the path is to the Program Files (x86) folder. For a 64-bit window on a 64-bit machine, the path is to the Program Files folder. See also MSBuildExtensionsPath32 and MSBuildExtensionsPath64.

Edit: To get to the 64 bit SVN folder, use :

<PropertyGroup>
   <TortoiseSVNPath>$(MSBuildExtensionsPath64)\..\TortoiseSVN\bin</TortoiseSVNPath>
</PropertyGroup>

Another way is to check for existence of folders:

<PropertyGroup>
  <TortoiseSVNPath Condition="Exists('$(PROGRAMFILES) (x86)')">$(PROGRAMFILES) (x86)\TortoiseSVN\bin</TortoiseSVNPath>
  <TortoiseSVNPath Condition="$(TortoiseSVNPath) == ''">$(PROGRAMFILES)\TortoiseSVN\bin</TortoiseSVNPath>
</PropertyGroup>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!