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

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

brettfo
Copy link
Contributor

@brettfo brettfo commented Dec 13, 2024

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 6MB JSON file that contains all of the SDK package mappings. 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 from a093517 to 5599bca Compare December 16, 2024 21:34
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.

1 participant