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?
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.
Right-click on the project (not the solution) in Solution Explorer and select Publish. In the Publish tab, select Publish.
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.
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?
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With