Are there any advantages to compiling an assembly

2019-06-19 22:41发布

Suppose I have a .Net Framework 3.5 SP1/CLR 2.0 application which needs to run on both x86 and x64 platforms. Suppose as well that for whatever reason, I need to create separate x86 and x64 installation programs.

As I have an x64-specific installer anyway, would there be any benefit to recompiling the application itself as x64 rather than targeting "AnyCPU"?

Does setting the target to x64 change anything at all besides the header information of the generated assembly?

4条回答
做个烂人
2楼-- · 2019-06-19 23:18

If you specify x64 it changes some default memory settings for the program, making it slightly more performant in programs with a large memory pressure. Larger thread stacks are allocated when compiling with x64 (link)

查看更多
SAY GOODBYE
3楼-- · 2019-06-19 23:25

I don't know much about .net assemblies, but in general, if you know that a program will only be executed in x64 architectures, compiling it in x64 machine code you'll get some performance improvement, and you will lose nothing (as long as you already know that it will only be executed in x64 environments).

查看更多
我只想做你的唯一
4楼-- · 2019-06-19 23:34

As long as you are not Ngen'ing any assemblies it would be better to leave as "AnyCPU", and let the JIT target the architecture.

查看更多
看我几分像从前
5楼-- · 2019-06-19 23:39

I've found than when I wrap a native x86 dll the wrapper assembly needs to be compiled for the x86 platform, otherwise I get a BadImageFormatException thrown on a x64 machine. Then it kind of snowballs, since all assemblies referencing that assembly also needs to be compiled for the x86 platform.

It could be that I'm just doing something wrong, but this is what I've found. If I wasn't using native dlls then I would leave all my assemblies as "AnyCPU".

查看更多
登录 后发表回答