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.

Exclude entire packages from single-file

See original GitHub issue

The problem

Actual situation

Unreasonably “fat” executables (due to code redundancy) when deploying multiple single-file executables (e.g. lots of small console based tools) that all depend on a set of shared libraries (part of them coming from nuget packages).

Expected situation

An easy way to exclude entire nuget packages (and their implicit dependencies) from single-file deployment.

Solution proposals

Solution 1

Allow ExcludeFromSingleFile to work on PackageReference similar to how it works on ProjectReference. Also, it should affect all implicit dependencies.


Solution 2

An option to generate a single-file (apphost + main assembly + required jsons) without embedding any other referenced assemblies. Then the user may opt-in for embedding specific assemblies via IncludeInSingleFile for a PackageReference and / or ProjectReference. Basically this would be the logical inversion of Solution 1.

Additional context

Just an example regarding my particular use case.

I have several (8 for the moment) small(ish) console based tools (~ 150 KB - 1 MB / program), all depending on a set of shared libraries (~ 10 MB in total). I’m doing single-file framework-independent deployments because I cannot enforce the client to do a system wide install of the .NET framework. The actual deployed package is just an archive with all the tools together, the client just unpacks it and uses the tools. The sad thing is that the useful code for each program is just insignificant noise compared to the actual file size.

Some stats on various publishing options:

  • –self-contained -p:PublishSingleFile=true Each tool is ~ 70 MB Everything is ~ 550 MB

  • –self-contained -p:PublishSingleFile=true -p:PublishTrimmed=true Each tool is ~ 25 MB Everything is ~ 200 MB

  • –self-contained -p:PublishSingleFile=true -p:PublishTrimmed=true -p:EnableCompressionInSingleFile=true Each tool is ~ 20 MB Everything is ~ 150 MB

  • –self-contained -p:PublishSingleFile=false Each tool is ~ 150 KB - 1 MB (as desired) Everything is ~ 80 MB A lot of files to deploy, a chaotic mix of native shared libraries, assemblies, executables and jsons

In the end I’m using the last variant combined with some hacks. I build each project separately with PublishSingleFile=true so the generated executable won’t require json files alongside them, but also don’t embedded all shared libraries (i.e. don’t use nuget packages, only explicit assembly references, set ExcludeFromSingleFile accordingly etc.). On top of that, adding insult to the injury, I had to do a dirty little hack by patching to workaround a bug that - while simple by itself - it was critical for a console program (see, many thanks to @vitek-karas for already fixing it).

Is it possible (or could it be made possible in the future) for the self-contained deployments to have all required framework specific files (native and managed libraries) in a sub-directory (e.g. ./CoreLibs), all business specific files (native and managed libraries) in another sub-directory (e.g. ./UserLibs) and keep the base directory (e.g. ./) “clean” with only executables in it?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:6
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

nietrascommented, Mar 29, 2023

Using LLM I came up with a way to exclude certain nuget package dlls as part of build by:

  <Target Name="ExplicitRemoveFromFilesToBundle" BeforeTargets="GenerateSingleFileBundle" DependsOnTargets="PrepareForBundle">
      <FilesToRemoveFromBundle Include="@(FilesToBundle)" Condition="$([System.String]::new('%(Filename)').ToLower().Contains('.model.')) AND ('%(Extension)' == '.dll')" />
    <Message Text="FilesToRemoveFromBundle '@(FilesToRemoveFromBundle)'" Importance="high" />
      <FilesToBundle Remove="@(FilesToRemoveFromBundle)" />

  <Target Name="CopyFilesToRemoveFromBundle" AfterTargets="Publish">
    <Copy SourceFiles="@(FilesToRemoveFromBundle)" DestinationFolder="$(PublishDir)" />
    <Message Text="Copied files to remove from bundle to '$(PublishDir)'" Importance="high" />

“It should remove the files that contain “.model.” and end with “.dll” from the single file bundle and copy them to the publish directory.”

nietrascommented, Mar 29, 2023

We have some very large nuget packages, that we don’t want to embed into a single file application, so was sad to see there apparently is no way to actually do that using current approach. I hope this is revisited for .NET 8 time frame, but hope there is some kind of workaround? Perhaps via one can make a target where particular files can be removed from FilesToBundle?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to exclude a single file from package with setuptools ...
The easiest way to remove a single, or at least a few specific files, from a package with setuptools is just to use...
Read more >
Can I exclude a folder and all contents except a single file?
I am trying to backup a home folder and I would like to exclude a sub folder and all files inside of it...
Read more >
Excluding files from projects | PhpStorm Documentation
In the Exclude files field, type the masks that define the names of files and folders to be excluded, for example, *.min.js or...
Read more >
yum/rpm: exclude a file (by path) from being installed
I don't want to have to rebuild an entire RPM from source just to exclude a single file from being installed.
Read more >
Create a single file for application deployment - .NET
In this article. Sample project file; Publish a single-file app; Exclude files from being embedded; Include PDB files inside the bundle ...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found