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?
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?
I'm not talking about the runtime but the unnecessary framework DLLs like the one I mentioned in the post.
Since
Microsoft.NETCore.App
depends on them, you need them. I asked a similar question and while Microsoft is making a CoreRT runtime to make a single deployment file in the future, it is still a work in progress.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!
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.