Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • C:\Program Files\Microsoft Visual Studio 9.0\SmartDevices\SDK\SDKTools\cabwiz.exe

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:

  • C:\Program Files (x86)\Microsoft Visual Studio 9.0\SmartDevices\SDK\SDKTools\cabwiz.exe

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?

like image 312
Vaccano Avatar asked Aug 17 '10 17:08

Vaccano


People also ask

How do I find my MSBuild version?

There is no way to determine which version of MSBuild was used. There is no days in the executable that says which version was used and nothing in them specific to MSBuild to use as a trail of breadcrumbs to determine it either. You dont even need MSBuild to build an executable.

How is 64-bit version better than the 32-bit MSBuild version?

Simply put, a 64-bit processor is more capable than a 32-bit processor because it can handle more data at once. A 64-bit processor can store more computational values, including memory addresses, which means it can access over 4 billion times the physical memory of a 32-bit processor. That's just as big as it sounds.

What is x86 and x64 in Visual Studio?

x86 refers to a 32-bit CPU and operating system while x64 refers to a 64-bit CPU and operating system.

What version of MSBuild does vs2022 use?

Visual Studio 2022 uses the 64-bit version of MSBuild for all builds. The 32-bit version is still available but we recommend switching all builds to the 64-bit version.


1 Answers

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>
like image 112
Aaron Jensen Avatar answered Sep 21 '22 07:09

Aaron Jensen