msbuild64-bitmsbuild-propertygroup

Find out the "Bit"ness of the current OS in MSBuild


I have a build script that needs to hard code a path to an executable. The path is:

This has worked fine, but now I am running on a 64 bit OS (but my coworker and build server are on 32 bit still).

I need the path to be this for me:

But use the normal path for the others.

Here is how I set it up:

<PropertyGroup>
    <CabWiz>"C:\Program Files\Microsoft Visual Studio 9.0\SmartDevices\SDK\SDKTools\cabwiz.exe"</CabWiz>
</PropertyGroup>

Is there a condition I can put on that so that I can set it if the OS (not the current build configuration) is 64 bit?


Solution

  • There is a registry key that will tell you the bit-edness of the current OS. Here are the properties I use in my MSBuild files:

    <PropertyGroup>
            <MachineProcessorArchitecture>$(registry:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment@PROCESSOR_ARCHITECTURE)</MachineProcessorArchitecture>
            <Is32Bit>False</Is32Bit>
            <Is32Bit Condition="'$(MachineProcessorArchitecture)' == 'x86'">True</Is32Bit>
            <Is64Bit>False</Is64Bit>
            <Is64Bit Condition="'$(MachineProcessorArchitecture)' == 'AMD64'">True</Is64Bit>
    </PropertyGroup>