Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing .net core 5.0 into single exe file

Tags:

c#

Can anybody help me. I'm trying to publish my .net core console app into single file.

I'm using this command:

dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true

I'm expecting that it will create a single file. But still there's dll files:

clrcompression.dll
clrjit.dll
coreclr.dll
mscordaccore.dll

How I can fix it? I already search but that's the same result

like image 702
mark123 Avatar asked Dec 03 '20 21:12

mark123


People also ask

What is a self-contained exe?

Publishing your app as self-contained produces a platform-specific executable. The output publishing folder contains all components of the app, including the . NET libraries and target runtime. The app is isolated from other . NET apps and doesn't use a locally installed shared runtime.

How do I publish a single file in DotNet?

The PublishSingleFile Flag. All that intro and it literally comes down to a single command flag : dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true. All this does is runs our publish command but tells it to package it within a single file. You’ll notice that we no longer specify the self-contained flag.

How to include DotNet runtime DLLs into an executable?

To include the dotnet runtime dlls into your executable, you need to also use the --self-contained flag. So you can run dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true --self-contained true. Show activity on this post.

How to publish single file in Visual Studio?

So you can run dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true --self-contained true. Show activity on this post. If using visual studio, go Build-> Publish [yourprojectname], edit the profile and check Produce single file.

How to publish DLLs in a binary file?

Use the following command dotnet publish -r win-x64 /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true this will embed the .dlls in the binary therefore in the publish folder will remain only a .pdb file which isn't necessary during runtime. Thanks for contributing an answer to Stack Overflow!


2 Answers

To bundle native libraries you need to specify the IncludeNativeLibrariesForSelfExtract flag.

So try running this dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true /p:IncludeNativeLibrariesForSelfExtract=true

See https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file#other-considerations

like image 144
Änis Avatar answered Oct 16 '22 16:10

Änis


To include the dotnet runtime dlls into your executable, you need to also use the --self-contained flag. So you can run dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true --self-contained true.

See https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file

like image 42
bisen2 Avatar answered Oct 16 '22 15:10

bisen2