6

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?

Asik
  • 21,506
  • 6
  • 72
  • 131

2 Answers2

4

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?

Community
  • 1
  • 1
NightOwl888
  • 55,572
  • 24
  • 139
  • 212
  • I'm not talking about the runtime but the unnecessary framework DLLs like the one I mentioned in the post. – Asik Mar 11 '18 at 00:50
  • 1
    Since `Microsoft.NETCore.App` depends on them, you need them. I asked a [similar question](https://stackoverflow.com/a/44840894) and while Microsoft is making a [CoreRT runtime](https://github.com/dotnet/corert) to make a single deployment file in the future, it is still a work in progress. – NightOwl888 Mar 13 '18 at 13:17
  • Is there any way to publish a Windows Service written in core 2.0 in FDD flavor? I am stuck here as 3 microservices take 310mb storage on my host - ridiculous, I am about to ditch core development! – Code Guru Jul 13 '18 at 14:12
  • I had the same confusing (why are so much dll's copied to the publish-folder) so thanks for both - the meaningful question and also answer. So I go with Self-contained Deployment for now as I don't have to install the runtime separately on the server and have the full control to my app environment this way. – FredyWenger Sep 06 '18 at 08:47
3

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!

Community
  • 1
  • 1
Major
  • 5,948
  • 2
  • 45
  • 60