Due to lack of 64 bit version of few COM libararies, we faced a situation to run our AnyCPU application into 32 bit. You can do this either by setting the Platform target or by using the corflags command.
Using Platform target feature. - This is the simple solution, you can change the Platform target settings from Project Properties > Build tab.
This will cause the compiler to set the 32Bit flag in the CLR header of the corresponding assembly. Every time we run this application no matter on what type of OS it will execute as a 32bit process. But this solution although simple and straight forward was not a viable solution for us since â€“ as mentioned above â€“ we want to have one and only one version of our product. Thus all components of our package have to be compiled with Platform Target set to Any CPU.
From VS 2011 onwards there is new compiler flag available “Prefer 32-bit”, which will help a .NET application compiled to x86 will fail to run on an ARM Windows system, but an “Any CPU 32-bit preferred” application will run successfully. Also, the “Prefer 32-bit” checkbox is only enabled for .NET 4.5+ executable projects.
Using corflags command - Similar to the above solution, here as well we are setting the CLR header to 32 bit using a tool called corflags - You can find more details about this tool here. To set the 32Bit flag, open the Developer Command prompt, navigate to the directory where your assembly is and use this command.
You can use this solution as part of the build, so that you can switch to x64 in future, developer don’t need to worry about any platforms.