Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Trimming fails for .NET Framework projects that use PackageReference #667

Closed
jnm2 opened this issue Mar 6, 2018 · 18 comments
Closed

Trimming fails for .NET Framework projects that use PackageReference #667

jnm2 opened this issue Mar 6, 2018 · 18 comments
Assignees

Comments

@jnm2
Copy link

jnm2 commented Mar 6, 2018

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?

@jnm2
Copy link
Author

jnm2 commented Mar 6, 2018

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

@jnm2
Copy link
Author

jnm2 commented Mar 6, 2018

Would repro projects help?

@ericstj
Copy link
Member

ericstj commented Mar 8, 2018

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

@ericstj ericstj changed the title Root package was specified but was not found in PackageDependencies Trimming fails when package specifies PrivateAssets=All Mar 8, 2018
@ericstj
Copy link
Member

ericstj commented Mar 8, 2018

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: #626

@jnm2
Copy link
Author

jnm2 commented Mar 8, 2018

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

@ericstj
Copy link
Member

ericstj commented Mar 8, 2018

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.

@ericstj ericstj changed the title Trimming fails when package specifies PrivateAssets=All Trimming fails for .NET Framework projects that use PackageReference Mar 8, 2018
@jnm2
Copy link
Author

jnm2 commented Mar 8, 2018

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?

@ericstj
Copy link
Member

ericstj commented Mar 8, 2018

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.

@jnm2
Copy link
Author

jnm2 commented Mar 8, 2018

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

@ericstj
Copy link
Member

ericstj commented Mar 12, 2018

Fixed with #671

@ericstj ericstj closed this as completed Mar 12, 2018
@jnm2
Copy link
Author

jnm2 commented Mar 12, 2018

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

@ericstj
Copy link
Member

ericstj commented Mar 12, 2018

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.

@ericstj
Copy link
Member

ericstj commented Mar 12, 2018

Package is available: 1.1.0-preview1-26312-02

@godefroi
Copy link

@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?

@ericstj
Copy link
Member

ericstj commented Jun 19, 2018

Yes I will publish an update.

@godefroi
Copy link

Thanks!

@ericstj
Copy link
Member

ericstj commented Jun 19, 2018

It is published now

@godefroi
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants