IncludeNativeLibrariesForSelfExtract includes XML and other files into output binary
See original GitHub issueDescription
I’m building a command line tool and want a single executable. Since PublishSingleFile
does not publish a single file (seriously…), I found on the web that the additional IncludeNativeLibrariesForSelfExtract
property is required.
The project has 4 data files in a data
folder with property CopyToOutputDirectory
set to PreserveNewest
.
Issue
The problem is that after publishing (dotnet publish -c Release) half of the data are missing in the data
folder. In addition, at least one of those file is (the XML one) is actually included in the executable binary instead of being outputted to the file system.
Step to reproduce
- Clone the following repository: https://github.com/titanix/BonetCLI
- Use the following project file instead of the one in the repository:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Nullable>disable</Nullable>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<PublishTrimmed>true</PublishTrimmed>
<PublishReadyToRun>true</PublishReadyToRun>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="HyperGraph.Core" Version="3.4.0" />
<PackageReference Include="HyperGraph.Extras" Version="3.4.0" />
</ItemGroup>
<ItemGroup>
<None Update="data\ids.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="data\ids.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="data\wiki.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="data\bonet.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
- Publish the project (dotnet publish)
- You can see that
ids.txt
andids.xml
are missing from thedata
folder. Looking at the binary content with an hex editor shows that the XML file is included in the executable. While I’m not sure ifids.txt
is included as well, the binary contains the following two strings:data/ids.txt
anddata/ids.xml
and it’s missing from the data folder, so I guess it included as well in the binary.
Configuration
Dotnet 5.0.302
Windows 11 (10.0.22000 Build 22000)
x64
Issue Analytics
- State:
- Created 2 years ago
- Comments:26 (19 by maintainers)
Top Results From Across the Web
Create a single file for application deployment - .NET
Bundling all application-dependent files into a single binary provides an application developer with the attractive option to deploy and ...
Read more >PublishSingleFile with WindowsAppSDKSelfContained ...
There is an option to set a flag, IncludeNativeLibrariesForSelfExtract, to include native libraries in the single file bundle, ...
Read more >xml - How do I pack a file together with the binary of a C++ ...
If you want it packaged inside the executable, you could consider simply creating a variable to hold it, something like (not really valid ......
Read more >Notarizing .NET Console Apps for macOS - Ken Muse
The process of signing the code alters the executable. For console applications, the signature is appended to the binary file. For .app packages ......
Read more >Extract XML from a binary file? : r/PowerShell
That might be a bit rough on a file with mixed binary and text. There may not even be be a line break....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@titanix FWIW, the problem is gone when using net8.0.
@titanix - Sure, and thanks for reporting the issue!!
The workaround is just to make sure you are not blocked while the bug is being investigated/fixed.