views:

55

answers:

2

After having found the answer to my question about the 64-bit version of MSBuild attempting to load 32-bit extensions, it has now become necessary for me to determine whether the 64-bit or 32-bit version of MSBuild is running so I can load the correct version of the DLL.

I can check the $(MSBuildBinPath) variable against a list of known paths, but that will not work if MSBuild is running from some non-standard location. This is not an elegant solution.

Is there some way to reliably determine whether the currently running MSBuild (or other process hosting the MSBuild engine) is 32-bit or 64-bit?

A: 

There is a related question at http://stackoverflow.com/questions/3505285/find-out-the-bitness-of-the-current-os-in-msbuild. In that question there is an answer by Blindy stating:


On a 64-bit OS, the following variables are defined:

ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)

So just test for ProgramFiles(x86) and if it's empty, use ProgramFiles.

Sayed Ibrahim Hashimi
I don't care what the bitness of the current os is, I need the bitness of the current *PROCESS*.
Mark
+1  A: 

Have you considered writing a custom MSBuild task that returns bitness of the current process?

See http://stackoverflow.com/questions/336633/how-to-detect-windows-64-bit-platform-with-net for an example.

Arnold Zokas
Yes, I believe that this is going to be the only way... If only there were something that didn't require a whole new task...
Mark
If you are using MSBuild 4.0, you could write an inline task (http://msdn.microsoft.com/en-us/library/dd722601.aspx ). This would save you having to create a custom task assembly.
Arnold Zokas