Why packed xll is smaller than dll with `PublishSingleFile`
Here is my output dir:
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 2025/9/19 15:27 publish
-a---- 2025/9/19 15:27 311 AmWPSAddin.dna
-a---- 2025/9/19 15:27 733184 AmWPSAddin.xll
-a---- 2025/9/19 15:27 311 AmWPSAddin64.dna
-a---- 2025/9/19 15:27 658944 AmWPSAddin64.xll <------ Much smaller
-a---- 2025/9/19 15:27 2502656 AmWPSAddinXll.dll <------- Much bigger
-a---- 2025/9/19 15:27 441256 AmWPSAddinXll.pdb
-a---- 2024/5/21 15:07 26112 GraphQL.Client.Abstractions.dll
-a---- 2024/5/21 15:07 19456 GraphQL.Client.Abstractions.Websocket.dll
-a---- 2024/5/21 15:07 82432 GraphQL.Client.dll
-a---- 2024/5/21 15:07 22016 GraphQL.Client.Serializer.Newtonsoft.dll
-a---- 2024/5/21 15:06 24576 GraphQL.Primitives.dll
-a---- 2025/9/16 16:04 721320 Newtonsoft.Json.dll
-a---- 2025/5/19 5:22 164864 Serilog.dll
-a---- 2025/4/28 8:38 38912 Serilog.Sinks.File.dll
-a---- 2020/2/19 18:05 20856 System.Buffers.dll
-a---- 2024/3/20 3:38 189104 System.Diagnostics.DiagnosticSource.dll
-a---- 2022/5/8 11:31 142240 System.Memory.dll
-a---- 2018/10/5 10:36 72192 System.Net.WebSockets.Client.Managed.dll
-a---- 2018/5/15 21:29 115856 System.Numerics.Vectors.dll
-a---- 2023/5/19 13:42 1358928 System.Reactive.dll
-a---- 2021/10/23 7:40 18024 System.Runtime.CompilerServices.Unsafe.dll
-a---- 2023/10/31 23:09 74000 System.Threading.Channels.dll
-a---- 2020/2/19 18:05 25984 System.Threading.Tasks.Extensions.dll
I tried to use dotnet PublishSingleFile feature to contains all depends lib in one dll and than pack it into xll. But I found that it seems compiled in incorrect order
- generate small dll
- exceldna pack a small xll
- dotnet generate a big dll
Here is my project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<UseWindowsForms>true</UseWindowsForms>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>false</SelfContained>
<LangVersion>10.0</LangVersion>
</PropertyGroup>
<PropertyGroup>
<ExcelAddInFileName>AmWPSAddin</ExcelAddInFileName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ExcelDna.AddIn" Version="1.9.0" />
<PackageReference Include="ExcelDna.Integration" Version="1.9.0" />
<PackageReference Include="ExcelDna.Interop" Version="15.0.1" />
<PackageReference Include="GraphQL.Client" Version="6.1.0" />
<PackageReference Include="GraphQL.Client.Serializer.Newtonsoft" Version="6.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="Serilog" Version="4.3.0" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="data_dict/*.json" />
</ItemGroup>
</Project>
The packed .xll files are under the "publish" directory. The .xll files in the Output directory that you show does not have the packed contents yet - they won't run without the other bits from this directory.
@govert The packaged xll in publish directory is nearly the same size of the out one. Currently the correct way to make it a really packed file is define all depends dlls in project_name.dna file. But if I remove the dna file, it will looks like
AmWPSAddin64-packed.xll ≈ AmWPSAddin64.xll < AmWPSAddin64.dll
- See the build output to see exactly what gets packed - it's logged in detail.
- If you have a hand-edited .dna file in the project directory, then only the
ExternalLibraryandReferencetags with Pack=true will specify assemblies to get packed. You can add more<Reference Path="..." Pack="true" />tags to pack more libraries - If you don't have a .dna file in your project, then the Excel-DNA build will create one. It will set up the main library output top get packed.
- When targeting .NET core, it will use the .deps.json file to decide what else must get packed.
- When targeting .NET Framework (as you are), you can add additional references to be packed by setting a project property like this
You can generate the include list from all the .dll files in the output directory like this<!-- Semicolon separated references list to include in .dna. --> <!-- Default value: empty --> <ExcelAddInInclude></ExcelAddInInclude><ItemGroup> <References Include="$(OutDir)*.dll" Exclude="$(OutDir)$(TargetFileName)"/> </ItemGroup> <PropertyGroup> <ExcelAddInInclude>@(References)</ExcelAddInInclude> </PropertyGroup> </Target>