Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish only required dependencies?

Tags:

c#

.net

.net-core

If I create a "Hello World" .NET Core C# Console application in Visual Studio 2017 and run

dotnet publish -c Release -r win10-x64 --self-contained

The resulting publish folder has 215 files in it, totals 62MB and includes the whole of .NET, which the application doesn't use. For example, it has System.Security.Cryptography.OpenSsl.dll.

This is part of the "Microsoft.NETCore.App" dependency which I seem to have no way to edit manually. How can I trim that down to what the application is actually using?

like image 796
Asik Avatar asked Mar 09 '18 19:03

Asik


People also ask

How do I change publish settings in Visual Studio?

Import the publish settings in Visual Studio and deployClick New or Create new profile. Select the option to import a profile. In the Publish dialog box, click Import Profile. Navigate to the location of the publish settings file that you created in the previous section.

How do you publish an AC project?

Right-click on the project (not the solution) in Solution Explorer and select Publish. In the Publish tab, select Publish.

What is self-contained app?

A self-contained application consists of a single, installable bundle that contains your application and a copy of the JRE needed to run the application. When the application is installed, it behaves the in the same way as any native application.


2 Answers

Per the deployment documentation:

Unlike FDD, a self-contained deployment (SCD) doesn't rely on the presence of shared components on the target system. All components, including both the .NET Core libraries and the .NET Core runtime, are included with the application

(emphasis mine)

If you don't want to deploy the whole .NET Core runtime along with your application, then you should use a Framework-dependent Deployment (FDD) instead of a Self-contained Deployment (SCD).

dotnet publish -c Release

In the future, the CoreRT runtime – which is still under development at the time of writing – aims to allow creating a single pre-compiled native executable that is specific to a runtime and does not require any other files.

Reference: Is there a way to make a console application run using only a single file in .NET Core?

like image 181
NightOwl888 Avatar answered Oct 26 '22 23:10

NightOwl888


There is a 3rd option as well: "Framework-dependent executables (FDE)"

You need to use --self-contained false e.g.:

dotnet publish <xyz.csproj> -c Release -r win-x64 --self-contained false

The 'Publish' folder still contains some Microsoft.*.dlls. However way less. In my case previous publish was folder size was 84MB now it is 12MB only!

like image 39
Major Avatar answered Oct 26 '22 23:10

Major