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

improve nuget package detection with SDK-managed packages #11127

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

brettfo
Copy link
Contributor

@brettfo brettfo commented Dec 13, 2024

This PR contains a temporary commit that redirects the smoke tests.

Consider the following example:

A repo contains a global.json file requiring the .NET SDK version 8.0.303. A project in that repo has a dependency on System.Text.Json/8.0.0 (either transitively or directly, it doesn't matter.)

When we detect dependencies, we run a restore operation, but the SDK takes special steps. During that operation, it sees the reference to System.Text.Json and realizes it has a newer copy, so it removes the reference.

The end result is that we don't report System.Text.Json as a reference because:

  1. The SDK pulled it out.
  2. The SDK replaced it with another version and we don't know what package that correlates to.

(Doing some manual checking, the version of System.Text.Json that the 8.0.303 SDK is using as a replacement is 8.0.4. This is important for later.)

If we then try to perform an update on System.Text.Json/8.0.4 => 8.0.5 we'll fail because that dependency wasn't reported.

This PR fixes that behavior.

When the special package is removed, we detect that then perform a lookup to see that the version of System.Text.Json that ships with the SDK 8.0.303 just so happens to match exactly with the NuGet package System.Text.Json/8.0.4. We then re-insert that dependency back into our reporting, because that's the equivalent package.

This way when we try to update System.Text.Json to version 8.0.5, we can correctly see that the dependency does exist as version 8.0.4 so the update then to 8.0.5 succeeds.

This was accomplished by adding a submodule to the dotnet/core repo and parsing and correlating several releases.json files with markdown files that list the relevant packages. The end result is a 3MB JSON file that contains all of the NuGet packages that shipped with a given runtime so we can map that System.Text.Json.dll was pulled out of the restore graph and it was replaced with one from Microsoft.NETCore.App.Ref/8.0.7 and that the corresponding version of System.Text.Json for that same runtime release was 8.0.4. This large mapping file is generated on build, so no manual steps need to be performed (and no huge file was added).

@github-actions github-actions bot added the L: dotnet:nuget NuGet packages via nuget or dotnet label Dec 13, 2024
@brettfo brettfo force-pushed the dev/brettfo/nuget-sdk-package-detection branch 3 times, most recently from 9521d2f to 0095890 Compare December 20, 2024 19:29
Copy link
Contributor

@ryanbrandenburg ryanbrandenburg left a comment

Choose a reason for hiding this comment

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

Nice one, mostly just nitpicking.

@brettfo brettfo force-pushed the dev/brettfo/nuget-sdk-package-detection branch 4 times, most recently from 3c4adc5 to 265c03d Compare January 8, 2025 19:44
@brettfo brettfo marked this pull request as ready for review January 8, 2025 20:06
@brettfo brettfo requested review from a team as code owners January 8, 2025 20:06
ryanbrandenburg
ryanbrandenburg previously approved these changes Jan 8, 2025
@brettfo brettfo force-pushed the dev/brettfo/nuget-sdk-package-detection branch from 265c03d to 9269f01 Compare January 9, 2025 16:55
randhircs
randhircs previously approved these changes Jan 9, 2025
@brettfo brettfo dismissed stale reviews from randhircs and ryanbrandenburg via 92623d8 January 9, 2025 17:32
@brettfo brettfo force-pushed the dev/brettfo/nuget-sdk-package-detection branch from 9269f01 to 92623d8 Compare January 9, 2025 17:32
@randhircs randhircs force-pushed the dev/brettfo/nuget-sdk-package-detection branch from 92623d8 to 00d66f6 Compare January 9, 2025 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: dotnet:nuget NuGet packages via nuget or dotnet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants