Skip to content

Disabling trimming per assembly with trimming does change the assembly #45598

Closed

Description

@NN---

Description

Specifying TrimmerRootAssembly and even IsTrimmable false does change the package file.

Configuration

.NET Core 3.1 or .NET 5.0

project.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <TrimmerRootAssembly Include="SMBLibrary" />

    <PackageReference Include="SMBLibrary" Version="1.4.3">
      <IsTrimmable>false</IsTrimmable>
    </PackageReference>
  </ItemGroup>
</Project>

program.cs

class Program { public static void Main() {} }

Run:
dotnet publish project.csproj -c Release -r win-x64 -o publish /p:PublishSingleFile=true /p:PublishTrimmed=true

Check file inside: obj\Release\netcoreapp3.1\win-x64\linked\SMBLibrary.dll

The file size is not the same as original file in
%userprofile%.nuget\packages\smblibrary\1.4.3\lib\netstandard2.0\SMBLibrary.dll

If you don't specify PublishTrimmed=true then the file is preserved but the resulting output is much bigger.

The expectation is that TrimmerRootAssembly preserves original file as described in documentation

Regression?

Not a regression.

Activity

  1. added
    area-AssemblyLoader-coreclr
    untriaged
    on Dec 4, 2020
  2. vitek-karas commented on Dec 4, 2020

    @vitek-karas
    Member

    This is currently expected. The trimmer still processes the assembly, it just doesn't remove any type/method from it in that mode. What it will do is remove assembly references to assemblies which are removed from the output. In this case it removes reference to mscorlib and netstandard and replaces it with references to .NET Core assemblies.

    Does the fact that assembly is modified (but not actually trimmed) cause problems for your application?

  3. NN--- commented on Dec 4, 2020

    @NN---
    ContributorAuthor

    It doesn't cause any issue but there are plenty of licenses which require you to state changes even if you just modify the date.
    Some licenses may even disallow such usage if you change the original file.
    For the safety I would like to have the original file in the output.

    https://tldrlegal.com/search?reverse=true&must[]=52c5e04809728f9723000009

  4. vitek-karas commented on Dec 4, 2020

    @vitek-karas
    Member

    Thanks for pointing that out!

  5. vitek-karas commented on Dec 4, 2020

    @vitek-karas
    Member

    This issue was moved to dotnet/linker#1669

  6. ghost locked as resolved and limited conversation to collaborators on Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-AssemblyLoader-coreclruntriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions