Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I shrink a dotnet publish package

I have recently started developing using dotnet core (as opposed to old fashion plain .net) to create a number of small utility console applications.

The development is fine and it has come to the point I want to publish them.

I am using the CLI and as I am only interested in Win 10 deployments, tried

dotnet publish -c release -r win10-x64

It worked and built me a "publish" folder where everything seemed to work, though the "publish" folder is huge (~70mb) compared to the size of the app (~500 lines of code).

As I am only going to deploy to Win10 machines is there a way to package this so I don't need all the .NET files? I thought that was what the -r option was for but that does not seem to have achieved much.

like image 452
BENBUN Coder Avatar asked Oct 22 '25 17:10

BENBUN Coder


1 Answers

It depends on how you want to deploy your app/who is going to use them.

The -r flag creates a self-contained app. This causes the publish command to include the necessary .NET Core DLL's for the specified platform (and platform specific nuget packages if they are avaiable), which means anyone can use the app without having to install .NET Core runtime.

If you remove the -r flag then publish will only include the DLL's for you app. But this means whoever wants to use your app must first install the .NET Core runtime.

You can see the difference by using the -o flag to write the publish output to different directories e.g.

dotnet publish -c release -r win10-x64 -o ./publish-win10

or

dotnet publish -c release -o ./publish-any

Now go and have a look at what has been written to ./publish-win10 and ./publish-any folders and you can the difference.

If you are installing them onto a system where the .NET Core runtime is already present then you can just distribute the DLL and save a lot of space. However if you want to be able to distribute the app without the end user having to worry about having the .NET Core runtime installed then the -r flag to create a self-contained distribution is the way to go, but results in the 'package' including the necessary .NET Core assemblies.

AFAIK the -r flag does not affect how you app is compiled, just what runtime DLL's are included as part of the publish command. So you always get the same DLL for your code if you publish it for win10-x64 or with, or without, the -r flag so your app DLL will run on any (.NET Core compatible) platform, but I am happy to be corrected on that point.

like image 112
Simply Ged Avatar answered Oct 25 '25 08:10

Simply Ged