gpt4 book ai didi

c# - WPF .exe - 大文件大小

转载 作者:可可西里 更新时间:2023-11-01 09:14:21 25 4
gpt4 key购买 nike

我正在处理 WPF 应用程序,发现 .exe 的大小超过 1.2MB。我想减少最终可执行文件的大小。代码也就200多kb,我在项目中用了几个.png的图片,加起来大概20kb。为什么最终的可执行文件这么大?我使用 ILDASM statistics 来查看 .exe 统计信息。发布以下输出:

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 大小? (以 Release模式 x64 构建项目)

更新:

我的构建选项是:

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

最佳答案

这可能是嵌入式资源的问题。

如果您向项目添加了图像或其他资源,即使您从项目中删除了该文件,该资源仍将保持嵌入状态。

检查项目属性的资源部分。

例如,您是否先将图像添加为位图,然后删除文件并添加为 png?

关于c# - WPF .exe - 大文件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20945064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com