In 64 bit versions of windows, 32 bit software is installed in “c:\program files (x86)”. This means you cannot use $(programfiles) to get the path to (32 bit) software. So I need a $(ProgramFiles32) to overcome this in my MSBuild project. I don’t want to change the project depending on the os it is running on.
I have a solution that I will post, but maybe there is a easier/better way.
In MSBuild 4.0+, there’s a
$(MSBuildProgramFiles32)property for it, which you can confidently employ directly (especially if you’re prepared to put aToolsVersion="4.0"at the top of the file to guarantee it’s going to be available and Fail Fast if it’s not).If you’re not and need something that can Do The Right Thing even when executed in an MSBuild 2.0 or later environment (i.e., back to VS 2005 environments), the complete solution is:
Unfortunately Progressive enhancement / polyfill overriding of the MSBuild reserved property name
MSBuildProgramFiles32via either a<PropertyGroup>or<CreateProperty>is rejected by MSBuild 4.0+ so it can’t be made tidier and still support .NET 2.0.