Skip to content

NativeAOT StripSymbols should allow options for what to do with the symbol file #33476

@eerhardt

Description

@eerhardt

In trying to make a minimally sized NativeAOT app in a Linux Docker container, the first thing a developer needs to do is set StripSymbols=true. The symbols in the app can bloat the app size by 2-3x.

However, the developer also needs to move the symbols out of their publish directory in order to actually save the size in the Docker image.

Typically, Dockerfiles will publish the app to a specific directory (using -o), and then copy that whole directory into the final container. Here's an example from https://docs.docker.com/samples/dotnetcore/:

# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app
    
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
    
# Copy everything else and build
COPY ../engine/examples ./
RUN dotnet publish -c Release -o out
    
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "aspnetapp.dll"]

Following this same pattern with PublishAot=true will still keep the .dbg file in the app, bloating the image.

We should add some options for what to do with the resulting "stripped" symbol file. Useful options I can think of:

  1. Don't publish the symbol file in the output folder. (It will still be in the obj folder)
  2. Specify a separate folder to publish the symbol file to

This way developers can simply set this setting in their .csproj (or Directory.Build.props), and they won't have to write work-around code like this in their Dockerfile:

# remove the symbols so they aren't part of the published app
RUN rm -rf /app/publish/*.dbg

cc @MichalStrehovsky

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions