Standard: Trimming fails for .NET Framework projects that use PackageReference

Created on 6 Mar 2018  路  18Comments  路  Source: dotnet/standard

The csproj has:

  <PropertyGroup>
    <TrimUnusedDependencies>true</TrimUnusedDependencies>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="SourceLink.Embed.AllSourceFiles" Version="2.7.4" PrivateAssets="all" />
    <PackageReference Include="Microsoft.Packaging.Tools.Trimming" Version="1.1.0-preview1-25818-01" />
  </ItemGroup>

It fails to build, giving:

Microsoft.Packaging.Tools.Trimming.targets(55,5): error MSB4018: The "TrimFiles" task failed unexpectedly.
System.Exception: Root package SourceLink.Embed.AllSourceFiles was specified but was not found in PackageDependencies
at Microsoft.DotNet.Build.Tasks.TrimFiles.GetPackageRoots(IDictionary`2 packages, Trimmable trimmable)
at Microsoft.DotNet.Build.Tasks.TrimFiles.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()

Is this expected to work?

All 18 comments

When I remove PrivateAssets="all", a separate PackageReference starts causing the same error even though it does not have PrivateAssets specified.

Would repro projects help?

I see what's happening. Updated the title of the bug and will put together a fix.

Actually, hold up I may have spoken too soon. Which version of the SDK are you using? It's possible that this change went through and I need to react to it: https://github.com/dotnet/standard/issues/626

This is a .NET Framework project building in the Visual Studio 15.6.1 IDE. That makes sense.

Got it. Reproducing now. The bug is due to missing the PackageDependency item completely in old NuGet targets, so similar to #626 but for a different reason. To workaround it you can set

  <PropertyGroup>
    <RootPackageReference>false</RootPackageReference>
  </PropertyGroup>

This will turn of our package graph rooting completely, but you'll still get the binary graph rooting. I'll need to bring back lock/asstets file reading to get the package graph for this and #626.

Great! I was looking for something like <RootPackageReference>false</RootPackageReference> earlier but didn't dig into the targets. Think a quick list of the interesting properties and items could be documented?

We have that here: https://github.com/dotnet/standard/blob/master/Microsoft.Packaging.Tools.Trimming/docs/trimming.md#additional-options though it could probably use some clean up (just reviewing now I see a number of typos). I'll make sure to give that some love when I address this issue as well.

Silly of me, I think I saw that before and missed the significance of RootPackageReference. It's already useful. Thanks!

Fixed with #671

@ericstj Very cool! Is there something I can subscribe to in order to know when a new prerelease is published?

Should be here: https://dotnet.myget.org/feed/dotnet-core/package/nuget/Microsoft.Packaging.Tools.Trimming. It builds daily, but I requested another build today since I missed this morning's sync point.

Package is available: 1.1.0-preview1-26312-02

@ericstj The latest version available from NuGet is 1.1.0-preview1-25818-01 which still has this issue. Can we get a newer version into NuGet?

Yes I will publish an update.

Thanks!

It is published now

Thanks, that version solved the issue for me. I appreciate the help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chrisaut picture chrisaut  路  3Comments

spottedmahn picture spottedmahn  路  5Comments

praeclarum picture praeclarum  路  5Comments

tbonham picture tbonham  路  5Comments

virzak picture virzak  路  4Comments