简体   繁体   中英

Is it good practice to design c# application under windows 64 bit?

I am new to c# . I am developing a C# application under windows 7 64 bit using visual studio 2015 professional. later when the application is ready I expect to install it in 64 bit or in 32 bit machines.

if I design the application under 64 bit I think it will not work under 32 bit, right? my question is: if I design it and then create setup file under 64 bit computer, what should I do later in order for my application to work under 32 bit windows machines?

Please help me. Thank you

if I design the application under 64 bit I think it will not work under 32 bit, right?

No. You can build an "Any CPU" assembly that will work in both. (You can also build a 32-bit assembly that will work in both, but on 64-bit it runs as a 32-bit app, which is rarely what you want).

my question is: if I design it and then create setup file under 64 bit computer, what should I do later in order for my application to work under 32 bit windows machines?

Test it in one. Selecting "Any CPU" is simple, but forgetting to do so is also simple, especially if you add another project for a library (an Any-CPU application with a 64-bit-only library is essentially 64-bit-only). Testing makes this very obvious, very soon.

With .net it doesn't matters, just stick to "Any CPU" compilations and you should not have any problem.

Only exception is if you're using external libraries for an specific platform (unmanaged libraries or managed libraries specifically compiled for x64),

In the case of managed libraries you will need to compile twice, one for x86 and other for x64 with the correct libraries, on the unamnaged case you just need to declare the DllImports twice, one for each platform and use at runtime the correct ones.

If it's a managed application, generally it won't matter. The run-time will auto-magicly sort most problems simply by using Any CPU as target.

I've met 2 problems mostly:

  1. developers who hard-code sizeof(int) to 4
  2. managed applications with un-managed dependancies (like openssl libraries) - in this case you will need to have 2 different builds (one for 32 bit and one for 64 bit)

Your QAs should test your application on all target systems (even if by using virtual machines to do so).

Most .NET developers (I can't speak for C++ guys) use 64bit systems simply because we want performance and to use the newest stuff. All new CPUs support 64 bit for quite some time. It's no longer something exotic.

It's a bit confusing to be honest...

... later when the application is ready I expect to install it in 64 bit or in 32 bit machines.

All 32-bit applications also work on 64-bit, because Intel/AMD made their AMD64 implementation backward compatible. In other words: regardless if you're using unmanaged or managed code, you can always run it on a 64-bit platform.

The other way around that's not the case, so:

if I design the application under 64 bit I think it will not work under 32 bit, right?

Yes, correct.

Personally I don't bother anymore with x86 because everyone nowadays has a 64-bit capable processor.

It's usually best to compile to 'Any CPU'. The 'x86' and 'x64' targets are only there to enforce a certain platform. In practice everything is always compiler to .NET IL - which is JIT compiled by the runtime to native assembler.

The JIT uses the 'target flag' or the 'prefer 32-bit' (csproj properties) hint to determine which runtime should run the code. If

  • you have the 'x86' target or
  • 'prefer 32-bit' (default) or
  • if you don't have a 64-bit system and don't have the 'prefer 32-bit' checked

it will use the x86 JIT compiler (and runtime). Otherwise it will use the x64 JIT compiler (and runtime).

There are some differences and subtleties that you change when you do this (that all have to do with native interop), but when you stick to normal C# code you shouldn't notice them.

Summary: Personally I seem to make it a habit of not being able to fit my application in 2 GB of RAM (I work what they now call 'big data'), so in those cases the best practice is to use the 'Any CPU' target and uncheck the 'prefer 32-bit'. That said, if you don't need the memory, it's probably better to leave it on as a safeguard.

my question is: if I design it and then create setup file under 64 bit computer, what should I do later in order for my application to work under 32 bit windows machines?

You might be surprised, but that's actually a totally different question. Setup systems (eg MSI) are highly dependent on the operating system. Most MSI's therefore use hacks to make it work on both platforms. Wix has some quite good documentation about this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM