Skip to content

Marking the application's assembly as trimmable passes completely wrong input to linker #13999

@vitek-karas

Description

@vitek-karas

Create a console app named "TrimApp"
Modify .csproj like this:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <Target Name="ConfigureTrimming"
          BeforeTargets="PrepareForILLink">
    <ItemGroup>
      <ManagedAssemblyToLink Condition="'%(Filename)' == 'TrimApp'">
        <IsTrimmable>true</IsTrimmable>
      </ManagedAssemblyToLink>
    </ItemGroup>
  </Target>

</Project>

Publishing this app with:

dotnet publish -r win-x64 /p:PublishTrimmed=true /p:TrimMode=link

Actually fails:

  TrimApp -> F:\ILLinker\repro\TrimApp\bin\Debug\net5.0\win-x64\TrimApp.dll
ILLink : error IL1020: No files to link were specified. Use one of '-a|-r|-x' options [F:\ILLinker\repro\TrimApp\TrimApp.csproj]

If I add a project reference to a simple classlib, then linker will actually not fail, but will be given command line where the classlib is treated as the "application assembly" - which leads to deleting the actual app's assembly from the output - producing completely broken app (without failing the build).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions