question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IncludeNativeLibrariesForSelfExtract includes XML and other files into output binary

See original GitHub issue

Description

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

  1. Clone the following repository: https://github.com/titanix/BonetCLI
  2. 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>
  1. Publish the project (dotnet publish)
  2. You can see that ids.txt and ids.xml are missing from the data 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 if ids.txt is included as well, the binary contains the following two strings: data/ids.txt and data/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:closed
  • Created 2 years ago
  • Comments:26 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
ALIENQuakecommented, Apr 6, 2023

@titanix FWIW, the problem is gone when using net8.0.

1reaction
VSadovcommented, Aug 20, 2021

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found