C
C#3mo ago
axo

✅ 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
axo
axoOP3mo ago
oh yeah if you have answers, pls ping on reply
qqdev
qqdev3mo ago
Are you using VS/VSC or Rider? Or none of the three? @axo
axo
axoOP3mo ago
visual studio code i interact with dotnet mainly through the terminal
qqdev
qqdev3mo ago
Is the .NET runtime present where you want to run the app? Or is it not present?
Angius
Angius3mo ago
$singlefile
MODiX
MODiX3mo ago
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:
<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, 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
axo
axoOP3mo ago
it is present, yes oh wow cheers
qqdev
qqdev3mo ago
What Z posted should help then :>
axo
axoOP3mo ago
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:
➜ sizeof yap.exe 70927890 ➜ sizeof main.exe 225792
➜ sizeof yap.exe 70927890 ➜ sizeof main.exe 225792
why are they so large?
qqdev
qqdev3mo ago
70mb vs 0.2mb
Angius
Angius3mo ago
No description
qqdev
qqdev3mo ago
Are you including the .NET runtime?
Angius
Angius3mo ago
The build includes the .NET framework An AoT build would be smaller Another way would be to trim it $trim
MODiX
MODiX3mo 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 than is necessary.
axo
axoOP3mo ago
how do you compile for AOT?
Angius
Angius3mo ago
$aot
MODiX
MODiX3mo ago
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.
Angius
Angius3mo ago
Just keep in mind there are limitations, no reflections for example
axo
axoOP3mo ago
makes sense
Lex Li
Lex Li3mo ago
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.
axo
axoOP3mo ago
understood, and thanks a ton for the help from everyone here how do i close a post? $close
MODiX
MODiX3mo ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?