I'd like to be able to distribute one version of an executable that a user can configure to run as either 32-bit or 64-bit. The service would have a 32-bit host process that would read configuration and launch new processes as 32 or 64-bit. 开发者_如何学GoWhat I haven't determined is how/if a executable targeted for Any CPU can be launched as a 32-bit process under 64-bit Windows.
This makes little sense. If your app can run as a 32-bit process and doesn't need the extra virtual memory space then there's just no point in ever running it as a 64-bit process.
Nor can you easily control it. It requires changing a value in the .exe header. The Corflags.exe utility can do this, but you cannot distribute it. Hacking the headers yourself is technically possible but very fugly. The ultimate obstacle is that you don't typically have the write access that's required to modify the .exe file on a properly secured machine (ie UAC). If you really, really need to do this then just deploy two copies of the .exe
Which you can do by writing a very puny bootstrapper .exe. All it needs to do is Assembly.Load() the main .exe and call its Program.Main() method. Build two versions of it.
Targeting Any CPU means that you are targeting the build machine's operating system. So if your build machine is 32-bit, then Any CPU will build a 32-bit output, and if your build machine is 64-bit, then you will get a 64-bit output. This has nothing to do with the machine you deploy to.
In order to achieve what you're looking to do, you will really need 2 copies of the exe, one as a 32-bit version and the other as 64-bit. You can do this by setting the Target platform to 32-bit and 64-bit respectively. Once again, if you target Any CPU, Visual Studio will pick up whichever OS is currently on the build machine.
精彩评论