繁体   English   中英

使用Numpy.NET NuGet package in C# class库 making.exe文件太大

[英]Using Numpy.NET NuGet package in C# class library making .exe file too big

我在 C# class 库中使用 Numpy.NET NuGet package 并且它在发布版本上生成的 making.exe 文件太大(从 ~10 到 ~30 MB)。 确切的原因是什么,这个问题有什么解决办法吗?

我使用 ILDASM 获取 .exe 文件的统计信息,这就是它显示的内容:

 File size            : 31318016
 PE header size       : 512 (472 used)    ( 0.00%)
 PE additional info   : 366928            ( 1.17%)
 Num.of PE sections   : 2
 CLR header size     : 72                 ( 0.00%)
 CLR meta-data size  : 157972             ( 0.50%)
 CLR additional info : 30706176           (-39.09%)
 CLR method headers  : 8741               ( 0.03%)
 Managed code         : 77296             ( 0.25%)
 Data                 : 367104            ( 1.17%)
 Unaccounted          : -366785           (-1.17%)

 Num.of PE sections   : 2
   .text    - 30950400
   .rsrc    - 367104

 CLR meta-data size  : 157972
   Module        -    1 (10 bytes)
   TypeDef       -  275 (3850 bytes)    8 interfaces, 0 explicit layout
   TypeRef       -  436 (2616 bytes)
   MethodDef     - 1598 (22372 bytes)   29 abstract, 0 native, 1537 bodies
   FieldDef      - 1013 (6078 bytes)    20 constant
   MemberRef     - 1210 (7260 bytes)
   ParamDef      - 1212 (7272 bytes)
   MethodImpl    -   65 (390 bytes)
   Constant      -  189 (1134 bytes)
   CustomAttribute- 1041 (6246 bytes)
   StandAloneSig -  210 (420 bytes)
   InterfaceImpl -   77 (308 bytes)
   PropertyMap   -  104 (416 bytes)
   Property      -  400 (2400 bytes)
   MethodSemantic-  731 (4386 bytes)
   TypeSpec      -  255 (510 bytes)
   Assembly      -    1 (22 bytes)
   AssemblyRef   -   27 (540 bytes)
   ManifestResource-   48 (576 bytes)
   NestedClass   -   68 (272 bytes)
   EventMap      -   19 (76 bytes)
   Event         -   28 (168 bytes)
   GenericParam  -   12 (96 bytes)
   MethodSpec    -  173 (692 bytes)
   GenericParamConstraint-    1 (4 bytes)
   Strings       - 50364 bytes
   Blobs         - 18320 bytes
   UserStrings   - 20924 bytes
   Guids         -    16 bytes
   Uncategorized -   234 bytes

 CLR additional info : 30706176
   Resources         - 30706176

 CLR method headers : 8741
   Num.of method bodies  - 1537
   Num.of fat headers    - 413
   Num.of tiny headers   - 1124
   Num.of fat sections   - 14
   Num.of small sections - 81

 Managed code : 77296
   Ave method size - 50

原来问题出在.csproj文件中。 它有以下几行,将 all.dll 嵌入到“AfterResolveReferences”事件中(不知道它是 VS 默认设置还是以前的开发人员故意这样做)。

<Target Name="AfterResolveReferences">
    <ItemGroup>
      <EmbeddedResource Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.Extension)' == '.dll'">
        <LogicalName>%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</LogicalName>
      </EmbeddedResource>
    </ItemGroup>
</Target>

我的 sln 有多个项目,主项目不需要此解决方案使用的所有库,因此我添加了条件以排除所有与 python 相关的库,它成功了。 这并没有伤害程序,因为使用 Numpy.net 的代码库项目在安装程序构建和 .exe 文件现在轻了 20 MB 之后仍然运行良好。 修改后的代码下方:

<Target Name="AfterResolveReferences">
    <ItemGroup>
      <EmbeddedResource Include="@(ReferenceCopyLocalPaths)" Condition="'%(ReferenceCopyLocalPaths.Extension)' == '.dll' And '%(ReferenceCopyLocalPaths.Filename)' != 'Numpy' And '%(ReferenceCopyLocalPaths.Filename)' != 'Python.Runtime' And '%(ReferenceCopyLocalPaths.Filename)' != 'Python.Included'
        And '%(ReferenceCopyLocalPaths.Filename)' != 'Python.Deployment'">
        <LogicalName>%(ReferenceCopyLocalPaths.DestinationSubDirectory)%(ReferenceCopyLocalPaths.Filename)%(ReferenceCopyLocalPaths.Extension)</LogicalName>
      </EmbeddedResource>
    </ItemGroup>
</Target>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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