✅ how to "publish" an app
yeah, i know, it sounds stupid, but i cannot for the life of me, figure out how to do this
all i want is a single final exe that i can run without needing any DLLs or PDBs or anything else
22 Replies
oh yeah if you have answers, pls ping on reply
Are you using VS/VSC or Rider?
Or none of the three? @axo
visual studio code
i interact with dotnet mainly through the terminal
Is the .NET runtime present where you want to run the app?
Or is it not present?
$singlefile
dotnet publish -c Release -r <runtime identifier> -p:PublishSingleFile=true
Use of -p:PublishSingleFile=true
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: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, but be aware of drawbacks and consider using an installer framework instead of that property with PublishSingleFile.
You might want to instead publish your application compiled Ahead Of Time to native code, see $nativeaot for examples.
Single file publishing | Runtime Identifier (RID) catalog | dotnet publish
it is present, yes
oh wow cheers
What Z posted should help then :>
quick question: i wanted to do a size comparison with C++ and C#'s "hello world" examples, and i wanted to know why this was the output:
why are they so large?
70mb vs 0.2mb

Are you including the .NET runtime?
The build includes the .NET framework
An AoT build would be smaller
Another way would be to trim it
$trim
Since .NET 6, publishing with
-p:PublishTrimmed=true
or
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-containedTrim 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 than is necessary.
how do you compile for AOT?
$aot
Native AOT deployment overview - .NET
Learn what Native AOT deployments are and why you should consider using it as part of the publishing your app with .NET 7 and later.
Just keep in mind there are limitations, no reflections for example
makes sense
When you bundle the standard C/C++ runtime with your C/C++ apps, they won't be small either, and should be of xx-MB size range (two digits). Like other comments indicated, AOT and trimming can reduce your .NET app+runtime smaller to a comparable size.
understood, and thanks a ton for the help from everyone here
how do i close a post?
$close
If you have no further questions, please use /close to mark the forum thread as answered