Skip to content

Publish AOT increases the assembly file size! #39012

@mahdighorbanpourptw

Description

@mahdighorbanpourptw

Comparing the published file using AOT and without AOT (but singleFile), I see a major difference in the size. In this bare example the difference is just about 3 MB, but in our production app is much more!
Publish SingleFile without AOT: 17MB
Publish with AOT: 38 MB
What could be the reason for this and how I can achieve the same level of size?

image

To Reproduce

dotnew new console -n TestAot
Add the follwoing to the csproj file:

<RuntimeIdentifiers>linux-x64</RuntimeIdentifiers>
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>partial</TrimMode>
<PublishAot>true</PublishAot>

Publish the project using the folowing command:
dotnet publish --configuration release -r linux-x64 --self-contained true /p:EnableCompressionInSingleFile=true -o ./linux-x64

Further technical details

.NET SDK:
Version: 8.0.200
Commit: 438cab6a9d
Workload version: 8.0.200-manifests.cdf2cc8e

Runtime Environment:
OS Name: ubuntu
OS Version: 22.04
OS Platform: Linux
RID: linux-x64
Base Path: /usr/share/dotnet/sdk/8.0.200/

.NET workloads installed:
There are no installed workloads to display.

Host:
Version: 8.0.2
Architecture: x64
Commit: 1381d5ebd2

.NET SDKs installed:
6.0.406 [/usr/share/dotnet/sdk]
8.0.200 [/usr/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.14 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.14 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
DOTNET_ROOT [/usr/lib/dotnet]

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-NativeAOTNative AOT compilationuntriagedRequest triage from a team member

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions