A
A
ATauenis2020-04-27 12:59:59
C++ / C#
ATauenis, 2020-04-27 12:59:59

How to build a lightweight assembly of a .NET Core application?

Previously, building a release version of a program on the .NET Framework was very easy. Select the Release/Any CPU configuration, and click Build. Everything. Then you can zip the Bin/Release folder, delete the pdb files, and you've got a finished distribution. It can already be packed into an installer, or distributed as a zip archive.

What about .NET Core? If you do it the same way, a bunch of "extra" dll and json files come out. But, in general, they don't weigh that much, you can also copy them to the archive with the release.

I read that in .NET Core you can build executables through dotnet publish, and you can immediately make binaries for alternative platforms. Everything would be fine, but the resulting folders "for publication" come out quite heavy - under 200 megabytes for a program weighing 0.2 MB!!! It's too fat, people will download ADSL forever (and there are such victims of capitalism, so far).

Are there civilized methods to cut the distribution of the program to a sane weight? Except how to delete by file, and see if it starts up or not somewhere on a clean OS.

This especially worries me because I found a good SDK plugin, https://github.com/qmfrederik/dotnet-packaging/. They can immediately receive deb/rpm packages for Linux and zip archives for Windows. But he, the bastard, uses the same dotnet publish, and simply archives its output (and supplements .deb packages with directives from the .csproj file). I would like the archives not to contain the entire .NET Core in its entirety. Moreover, on Linux, in any case, if something is downloaded by the package manager.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Korotenko, 2020-04-27
@ATauenis

Oh wai. In general, the advice is simple, remove dependencies, this applies to all sorts of roslins, generators for EF and other stuff that catches the studio. Plus, in the publishing settings, there is an option to publish the full version or a version for an already installed framework.
https://docs.microsoft.com/ru-ru/dotnet/core/deploying/
In addition, you can copy the files 1 time, and then simply replace the dll
. Alternatively, you can create an installer that installs the framework as needed.
For example WiX installer
Here is the working code without any garbage.

dotnet build -c Release-no-self
dotnet zip --no-restore -c Release-no-self

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RootNamespace>_444</RootNamespace>
    <Configurations>Debug;Release;Release-no-self</Configurations>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DebugType>pdbonly</DebugType>
    <DebugSymbols>true</DebugSymbols>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release-no-self|AnyCPU'">
    <SelfContained>False</SelfContained>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Packaging.Targets" Version="$(PackagingNuGetVersion)" />
  </ItemGroup>

  <PropertyGroup>
    <PostInstallScript>
    </PostInstallScript>
    <PostRemoveScript>
    </PostRemoveScript>
  </PropertyGroup>

  <Target Name="PackageZip" DependsOnTargets="CreateZip" Outputs="$(ZipPath)"/>
  <Target Name="PackageTarball" DependsOnTargets="CreateTarball" Outputs="$(TarballPath)"/>
  <Target Name="PackageDebian" DependsOnTargets="CreateDeb" Outputs="$(DebPath)"/>
  <Target Name="PackageRpm" DependsOnTargets="CreateRpm" Outputs="$(RpmPath)"/>

</Project>

F
freeExec, 2020-04-27
@freeExec

but the resulting folders "for publication" come out quite heavy - under 200 megabytes for a program weighing 0.2 MB!!!

So in the version with the .NET Framework, you must first download this 400MB framework and install it. It won't work without it. Therefore, the statement that the program weighs 0.2Mb is not true.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question