C
C#6mo ago
chx777

How to create a single self-contained executable of a dotnet 8 C# console app in vscode?

I am a beginner trying to learn C# on linux using vscode. When i run the command dotnet run, i know that an executable is created in the bin/debug folder. When i run the executable from within this folder it runs fine.But what i want is to be able to run a copy of this executable file from anywhere on my computer. I hope someone can help on this.
2 Replies
Jimmacle
Jimmacle6mo ago
$singlefile
MODiX
MODiX6mo 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. 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
Want results from more Discord servers?
Add your server