embed or hide package dlls

How can I embed or hide the package dlls into the exe or place them into a sub folder where the exe is at? There are over 200 dlls in the output build and its just ridiculous.
38 Replies
sibber
sibber3y ago
$singlefile
MODiX
MODiX3y ago
dotnet publish -c Release -r <runtime identifier> -p:PublishSingleFile=true Use of -r|--runtime implies --self-contained true. Add --self-contained false to publish as runtime-dependent. -r ... and -p:PublishSingleFile=true can be moved to .csproj as the following properties:
<RuntimeIdentifier>runtime identifier</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>runtime identifier</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
but to target multiple RIDs, you have to use dotnet publish with the -r option for each RID. You can also add -p:IncludeNativeLibrariesForSelfExtract=true to include native libraries (like Common Language Runtime dlls) in the output executable. https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file https://docs.microsoft.com/en-us/dotnet/core/rid-catalog https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish
Create a single file for application deployment - .NET
Learn what single file application is and why you should consider using this application deployment model.
.NET Runtime Identifier (RID) catalog
Learn about the Runtime Identifier (RID) and how RIDs are used in .NET.
sibber
sibber3y ago
you can also add -p:IncludeAllContentForSelfExtract=true
primetime43
primetime43OP3y ago
I have this and it doesnt seem to do it idk why
primetime43
primetime43OP3y ago
jcotton42
jcotton423y ago
@primetime43 you're publishing right? not just building
sibber
sibber3y ago
whats that stuff about an installer
primetime43
primetime43OP3y ago
im going to upgrade the target version rn to .NET 6 should have more flexibility then. Right now its targeting .net 5.0 well I was just going to build the exe then place it in the release on my github
jcotton42
jcotton423y ago
single file and friends only apply to publishes, not regular builds that is, dotnet publish, or the publish option in Visual Studio
primetime43
primetime43OP3y ago
oohhh
sibber
sibber3y ago
which is what you want builds dont include all the dependencies like nuget packages
jcotton42
jcotton423y ago
but bump to .net 6 first as 5 is out of support anyhow
primetime43
primetime43OP3y ago
wow it worked I got it to publish haha
primetime43
primetime43OP3y ago
primetime43
primetime43OP3y ago
ty both so much! okay ya I will went up to .net 6 and now I get this issue when trying to run it in vs
primetime43
primetime43OP3y ago
primetime43
primetime43OP3y ago
its a 2016 sln file I believe, so maybe I need to some how update that to 2022? wow, getting rid of this fixed it. Super weird <PublishSingleFile>true</PublishSingleFile> but now when I publish it doesnt do with single file, so not a good fix. hmm
Chiyoko_S
Chiyoko_S3y ago
pass publishsinglefile only when building, could do it from commandline manually by doing /p:PublishSingleFile=true it also should be possible to make it happen automatically using some MSBuild-fu but I don't have the knowledge :p
primetime43
primetime43OP3y ago
hmm shouldnt be like that I dont think...
Chiyoko_S
Chiyoko_S3y ago
I do remember running into similar situation with debugger failing to attach when I have some publish related properties defined in csproj
Chiyoko_S
Chiyoko_S3y ago
GitHub
Support Single File Diagnostics · Issue #45382 · dotnet/runtime
This issue is tracking the work necessary to support single-file diagnostics. Our goal is to deliver parity with debugging and profiling with framework dependent applications where applicable. Redu...
Chiyoko_S
Chiyoko_S3y ago
yeahhhhhh so it is how it is due to how visual studio grabs stuffs from publish output apparently <PublishSingleFile Condition="'$(Configuration)' == 'Release'">true</PublishSingleFile>
primetime43
primetime43OP3y ago
oh damn so its a bug that still hasnt been fixed after like 2 years
primetime43
primetime43OP3y ago
primetime43
primetime43OP3y ago
thats the only work around rn
Chiyoko_S
Chiyoko_S3y ago
welllll I assume it's more of a VS issue or something
primetime43
primetime43OP3y ago
well it worked in .net 5 but not 6, so it seems to be a .net issue
Chiyoko_S
Chiyoko_S3y ago
the sdk is probably doing nothing wrong, it's told to publish and publish single file but vs is trying to grab nonexistent file or something
primetime43
primetime43OP3y ago
thats weird that such a large feature like this was overlooked
Chiyoko_S
Chiyoko_S3y ago
same tbh
primetime43
primetime43OP3y ago
its not like PublishSingleFile isnt something a lot of ppl dont use ya know yep using this fixed it for debug, but not release mode
<PublishSingleFile Condition="'$(Configuration)' == 'Release'">true</PublishSingleFile>
<PublishSingleFile Condition="'$(Configuration)' == 'Release'">true</PublishSingleFile>
@Chiyoko_S even with this code ^ it allows me to run in debug mode with no issue, but release gives that error and publish doesnt pack it into a single file
Chiyoko_S
Chiyoko_S3y ago
1. debugging in release is always kinda wonky as a lot of the info necessary are missing & there's optimisations that goes in making debugging harder 2. did you specify -c Release when dotnet publishing
primetime43
primetime43OP3y ago
I mean I tried both, publishing in either doesnt pack it um I didnt do it from the command line, I did it from in VS, but ill try it through cl
Chiyoko_S
Chiyoko_S3y ago
hm perhaps you need to clear out the output folder I don't know it's totally a guess but
primetime43
primetime43OP3y ago
ya I did that also
Chiyoko_S
Chiyoko_S3y ago
hm
primetime43
primetime43OP3y ago
hmm if I figure it out, ill let you know @Chiyoko_S fixed it had to add this to the .csproj file <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
Chiyoko_S
Chiyoko_S3y ago
ah
Want results from more Discord servers?
Add your server