Warm tip: This article is reproduced from stackoverflow.com, please click
.net .net-core c#

How to publish only required dependencies?

发布于 2020-03-27 10:25:15

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?

Questioner
Asik
Viewed
84
NightOwl888 2018-03-13 21:16

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?