本文介绍了WPF .exe-大文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用WPF应用程序,发现.exe大小超过1.2MB。我想减小最终可执行文件的大小。代码不超过200 Kb,我在项目中使用了几张.png图像,这些图像总共占用约20kb。为什么最终的可执行文件如此之大?我使用ILDASM统计信息来查看.exe统计信息。将输出发布到以下位置:

I am working on a WPF application and the .exe is found to be over 1.2MB in size. I would like to reduce the size of the final executable. The code is no more than a few 200 Kb, I use a few .png images in the project, which alltogether takes up about 20kb. Why is the final executable so big? I used ILDASM statistics to take a look at the .exe statistics. Posting the output below:

File size            : 1267712
 PE header size       : 512 (496 used)    ( 0.04%)
 PE additional info   : 1547              ( 0.12%)
 Num.of PE sections   : 3
 CLR header size     : 72                 ( 0.01%)
 CLR meta-data size  : 72524              ( 5.72%)
 CLR additional info : 1160002            (91.50%)
 CLR method headers  : 3189               ( 0.25%)
 Managed code         : 28702             ( 2.26%)
 Data                 : 2048              ( 0.16%)
 Unaccounted          : -884              (-0.07%)

 Num.of PE sections   : 3
   .text    - 1265152
   .rsrc    - 1536
   .reloc   - 512

 CLR meta-data size  : 72524
   Module        -    1 (10 bytes)
   TypeDef       -   58 (812 bytes)     0 interfaces, 0 explicit layout
   TypeRef       -  250 (1500 bytes)
   MethodDef     -  647 (9058 bytes)    0 abstract, 0 native, 639 bodies
   FieldDef      -  216 (1296 bytes)    10 constant
   MemberRef     -  481 (2886 bytes)
   ParamDef      -  460 (2760 bytes)
   MethodImpl    -   11 (66 bytes)
   Constant      -   11 (66 bytes)
   CustomAttribute-  506 (3036 bytes)
   StandAloneSig -   73 (146 bytes)
   InterfaceImpl -   27 (108 bytes)
   PropertyMap   -   29 (116 bytes)
   Property      -  233 (1398 bytes)
   MethodSemantic-  304 (1824 bytes)
   TypeSpec      -   30 (60 bytes)
   Assembly      -    1 (22 bytes)
   AssemblyRef   -   13 (260 bytes)
   ManifestResource-    2 (24 bytes)
   NestedClass   -   17 (68 bytes)
   EventMap      -    5 (20 bytes)
   Event         -    7 (42 bytes)
   MethodSpec    -   12 (48 bytes)
   Strings       - 21669 bytes
   Blobs         - 18740 bytes
   UserStrings   -  6244 bytes
   Guids         -    16 bytes
   Uncategorized -   229 bytes

 CLR additional info : 1160002
   Resources         - 1160002

 CLR method headers : 3189
   Num.of method bodies  - 639
   Num.of fat headers    - 169
   Num.of tiny headers   - 470
   Num.of fat sections   - 3
   Num.of small sections - 25

 Managed code : 28702
   Ave method size - 44

如您所见,CLR附加信息占据了大部分空间。我将项目中的所有视觉样式用作 StaticResource ,我认为这没有什么大不同? .exe大小怎么解释? (以发布模式x64构建项目)

As you can see, the CLR additional info takes up most of the space. I am using all visual styles in my project as StaticResource, which I think makes no big difference? How can the large .exe size be explained? (Building the project in release mode x64 )

更新:

我的构建选项是:

Configuration - Release
Platform - x64
Optimize code - enabled
Allow unsafe code - disabled
Conditional comppilation symbols - none


推荐答案

具有所有依赖项的间接引用默认样式通常在代码或XAML中不可见。我不确定,但是如果WPF将它们嵌入到exe中,则可能会导致一些开销。您可以通过删除大多数与WPF相关的代码来进行测试,以查看这是否会严重影响文件大小。

Indirectly referenced default styles with all dependencies they have are usually not visible in code or XAML. I am not sure but if WPF is embedding them into the exe, this could account for some of the overhead. You could test this by removing most of the WPF-dependent code to see whether this significantly influences file size.

由于WPF且可执行,因此也可能会产生开销。您可以通过将代码放入WPF自定义或用户控件库项目中进行测试。这可以由Visual Studio创建。如果对于相同的内容,生成的DLL比EXE文件小得多,则可能是WPF的组合,并且是可执行文件。

There could also be an overhead due to being WPF and being executable. You could test this by putting your code into a WPF Custom or User Control Library Project. This can be created by visual studio. If for the same content the resulting DLLs are much smaller than the EXE-files, it might be a combination of WPF and being an executable.

通常,我发现文件大小开销不足为奇。作为一个大框架,WPF的小巧性和效率众所周知。

In general, I find a file size overhead not surprising. As a big framework WPF is not known for its tininess and efficiency.

此处有两个答案:还是有帮助的。

The two comments to the answer here: "Why is my .net exe so huge" analyzer tool? might also be helpful.

这篇关于WPF .exe-大文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 13:34