Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide PrunePackageReference data for NuGet #45874

Merged
merged 9 commits into from
Jan 16, 2025

Conversation

dsplaisted
Copy link
Member

Provide PrunePackageReference data to NuGet (see the spec).

This implementation copies generated code from https://github.com/microsoft/component-detection/tree/main/src/Microsoft.ComponentDetection.Detectors/nuget/FrameworkPackages which encapsulates the data about which packages are included for each target framework and framework reference. This is a quick and easy way to get the PrunePackageReference support working, though it doesn't provide the best way for keeping this data up-to-date.

We will continue to work on designing a mechanism for this information to flow into the SDK and be updated with each release.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Infrastructure untriaged Request triage from a team member labels Jan 10, 2025
@dsplaisted dsplaisted requested review from nkolev92, ericstj and a team January 10, 2025 19:05
Copy link
Member

@Forgind Forgind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't have how the PrunePackageReference item (maybe tweak the name? sounds like a boolean value to me) is used. It looks like it should hold the highest value of each of the framework references, so if that's what nuget wants, then this looks right to me.

@@ -50,6 +51,21 @@ Copyright (c) .NET Foundation. All rights reserved.
</CreateWindowsSdkKnownFrameworkReferences>
</Target>

<PropertyGroup Condition="'$(PrunePlatformPackageReferences)' == ''">
<PrunePlatformPackageReferences>false</PrunePlatformPackageReferences>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this PropertyGroup?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was to set a default value, and even if it wasn't technically needed it made it easier to change the default value. But now I'm using NuGet's flag instead so this has been removed.

<PrunePlatformPackageReferences>false</PrunePlatformPackageReferences>
</PropertyGroup>

<Target Name="AddPrunePackageReferences" BeforeTargets="CollectPrunePackageReferences"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:
_AddPrunePackageReferences
?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have so many targets that don't start with the underscore, I'm not sure there's much value in adding it here.

@@ -0,0 +1,197 @@
namespace Microsoft.ComponentDetection.Detectors.NuGet;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need these when they're all out-of-support?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't hurt, it may help a bit, and it's easier to just copy all of the code from the folder in the component-detection repo rather than to pick and choose.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it helps for out of support frameworks. Less noise that folks need to deal with -- helps them see the key message
-- framework is out of support.

using System.Threading.Tasks;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Microsoft.ComponentDetection.Detectors.NuGet;
Copy link
Member

@joeloff joeloff Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will Microsoft.ComponentDetection.Detectors.NuGet trip up RPS module loads?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this isn't adding another DLL reference, there's just code that I've copied in from elsewhere that has a different namespace.

}
}

PackagesToPrune = packagesToPrune.Select(p =>
Copy link
Member

@ericstj ericstj Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we'll want a cache of these per framework? In case there is cost in constructing the items and value in sharing them for a given framework references & version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a cache in the latest commit, though I'm not sure it's really worth the risk right now, since this is an opt in feature and the tests won't really exercise the caching, so it's pretty much untested.

@dsplaisted
Copy link
Member Author

This doesn't have how the PrunePackageReference item (maybe tweak the name? sounds like a boolean value to me) is used. It looks like it should hold the highest value of each of the framework references, so if that's what nuget wants, then this looks right to me.

It's consumed by NuGet / the NuGet targets, so that's not part of this PR (or this repo, really). The spec covers how it works. The item name also needs to be the same as NuGet is using, so we can't just change that.

@dsplaisted
Copy link
Member Author

Testing note: I built the SDK repo with this change and package pruning enabled. Spot-diffing some assets files showed packages were pruned correctly. Perf-wise, the AddPrunePackageReferences target took 600 ms out of a1 minute 42 second build. That seems fine, and the overall build time might even be less since fewer packages are downloaded, passed to the compiler, etc.

@dsplaisted dsplaisted merged commit 4824934 into dotnet:release/9.0.2xx Jan 16, 2025
28 of 31 checks passed
@ViktorHofer
Copy link
Member

ViktorHofer commented Jan 16, 2025

@dsplaisted do you plan to dogfood this in our own stack, i.e. by turning in on in the Arcade SDK? Source-build would immediately benefit from it as it still needs to carry netstandard1.x packages around (in SBRP). cc @MichaelSimons

@dsplaisted
Copy link
Member Author

@dsplaisted do you plan to dogfood this in our own stack, i.e. by turning in on in the Arcade SDK? Source-build would immediately benefit from it as it still needs to carry netstandard1.x packages around (in SBRP). cc @MichaelSimons

Yes, we should do that. We need to make sure that the SDK used by our repos is updated to a version that supports this too.

@ViktorHofer
Copy link
Member

We will probably update the SDK in Arcade and the VMR sometime next week. I can ping you when that's done.

@nkolev92
Copy link
Contributor

@dsplaisted I'm guessing #44694 should now be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Infrastructure untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants