Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to compile C# Application for both 32 bit and 64 bit system
Posted
Comments
[no name] 17-Apr-14 18:43pm    
http://aspboss.blogspot.com/2010/06/how-to-compile-c-application-for-both.html

1 solution

You should use the target instruction-set architecture named "Any CPU", found in Visual Studio project properties, first tab "Application". If you are not using Visual Studio, see the structure of the project. If you are not using MSBuild projects, see the compiler command-line documentation.

Some background: .NET is based on JIT compilation: http://en.wikipedia.org/wiki/JIT_compiler[^].

So, the actual instruction-set architecture doesn't have to be prescribed in the executable file or its assembly manifest. During runtime, .NET will determine what CPU is used from OS and will take it into account while compiling your IL code to native instructions. For 64-bit architectures (it's not one but at least two, incompatible to each other), and application targeted as "AnyCPU" will always be executed in 64-bit mode. However, if your assemblies (or at least the entry-level assembly, others being set to "AnyCPU" or the same architecture and the entry-level) are targeted to x86, it will be executed as 32-bit, which is compatible with all other x86* or IE* architectures and is executed on the WoW64 subsystem: http://en.wikipedia.org/wiki/WoW64[^].

"AnyCPU" is compatible with any of the "concrete" architectures, but you never can mix up two assemblies targeted to different "concrete" architectures in the same application/process. It can even compile, but can crash during runtime.

The verdict on this: use "AnyCPU" as much as possible. Other target architectures are really needed for compatibility with some modules targeted for any "concrete" architecture, usually native (unmanaged) modules.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900