C
C#2y ago
wawa

❔ ✅ ✅ Why does $singlefile make the .exe file so large

Hey I didnt want loads of files so I used $singlefile method and now the exe is 64 megabytes for just a console.writeline hello world program does anyone have any idea of how to lower it
18 Replies
MODiX
MODiX2y 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 RID and -p:PublishSingleFile=true can be moved to .csproj as the following properties:
<RuntimeIdentifier>RID</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>RID</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. You might want to instead publish your application compiled Ahead Of Time to native code, see $nativeaot. 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.
Buddy
Buddy2y ago
Because the runtime is contained within the executable. And the runtime is big
ero
ero2y ago
Hello world is not 64 mb It's less than 2
wawa
wawaOP2y ago
how do i get rid of it using this dotnet publish -c Release -r win-x64 -p:PublishSingleFile=true
ero
ero2y ago
Just read $singlefile...?
MODiX
MODiX2y 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 RID and -p:PublishSingleFile=true can be moved to .csproj as the following properties:
<RuntimeIdentifier>RID</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>RID</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. You might want to instead publish your application compiled Ahead Of Time to native code, see $nativeaot. 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.
wawa
wawaOP2y ago
dotnet publish -c --self-contained=true Release -r win-x64 -p:PublishSingleFile=true Required argument missing for option: -c where would I put self contained
mtreit
mtreit2y ago
Required argument missing for option: -c
mtreit
mtreit2y ago
mtreit
mtreit2y ago
mtreit
mtreit2y ago
???
MODiX
MODiX2y ago
Sorry @Jb9 your message contained blocked content and has been removed!
wawa
wawaOP2y ago
sorry im actually a huge idiot thank you dotnet publish -c Release --self-contained=false -r win-x64 -p:PublishSingleFile=true for other people
sibber
sibber2y ago
you can trim too
wawa
wawaOP2y ago
what is that
sibber
sibber2y ago
$trim
MODiX
MODiX2y ago
Since .NET 6, publishing with -p:PublishTrimmed=true or
<PropertyGroup>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
<PropertyGroup>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
added to the .csproj file will publish a binary trimmed of all the unused framework code. https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/trim-self-contained
Trim self-contained applications - .NET
Learn how to trim self-contained apps to reduce their size. .NET Core bundles the runtime with an app that is published self-contained and generally includes more of the runtime then is necessary.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity. Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?