Skip to content

ASP.NET Core assemblies should participate in member-level trimming #29508

Closed
@mthalman

Description

@mthalman

When using the TrimMode=Link publish option, none of the ASP.NET Core assemblies are affected. They all remain at their full size even if members within those assemblies are never accessed by a code path in the application.

Because of the quantity and size of the ASP.NET Core assemblies, there is a big opportunity to reduce the size of a deployed app if these assemblies participated in member-level trimming.

As an example, this sample ASP.NET Core application has the following trimmed container image sizes on Alpine Linux:

TrimMode Size
<Default> 98.5 MB
Link 80 MB

If the ASP.NET Core assemblies participated in assembly-level trimming, this reduction would be even greater.

Repro steps:

  1. git clone https://github.com/dotnet/dotnet-docker.git
  2. cd dotnet-docker/samples/aspnetapp
  3. docker build -t default-trimming -f Dockerfile.alpine-x64-slim .
  4. Modify Dockerfile.alpine-x64-slim to include /p:TrimMode=Link in the dotnet publish call
  5. docker build -t link-trimming -f Dockerfile.alpine-x64-slim .
  6. docker inspect --format "{{ .Size }}" default-trimming
  7. docker inspect --format "{{ .Size }}" link-trimming

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions