-
Notifications
You must be signed in to change notification settings - Fork 1k
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
base: main
Are you sure you want to change the base?
Conversation
24720e9
to
9521d2f
Compare
9521d2f
to
0095890
Compare
There was a problem hiding this 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.
nuget/helpers/lib/NuGetUpdater/DotNetPackageCorrelation.Test/EndToEndTests.cs
Show resolved
Hide resolved
} | ||
|
||
var releasesJson = await File.ReadAllTextAsync(releasesJsonPath); | ||
var releasesFile = JsonSerializer.Deserialize<ReleasesFile>(releasesJson, SerializerOptions)!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick:
var releasesFile = JsonSerializer.Deserialize<ReleasesFile>(releasesJson, SerializerOptions)!; | |
var releasesFile = await JsonSerializer.DeserializeAsync<ReleasesFile>(releasesJson, SerializerOptions)!; |
private static partial Regex StandardLineWithFileExtensions(); | ||
|
||
[GeneratedRegex(@"^(?<PackageName>[^|\s]+)\s*\|\s*(?<PackageVersion>[^|\s]+)$", RegexOptions.Compiled)] | ||
// Some.Package | 1.2.3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to use examples here.
nuget/helpers/lib/NuGetUpdater/DotNetPackageCorrelation/Model/PackageMapper.cs
Show resolved
Hide resolved
@@ -388,6 +388,17 @@ public static MockNuGetPackage WellKnownReferencePackage(string packageName, str | |||
return WellKnownPackages[key]; | |||
} | |||
|
|||
public static MockNuGetPackage GetMicrosoftNETCoreAppRefPackage(int majorRuntimeVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
{ | ||
var removedPackageName = GetChildMetadataValue(removedAssembly, "NuGetPackageId"); | ||
var removedFileName = Path.GetFileName(removedAssembly.Name); | ||
if (removedPackageName is not null && removedFileName is not null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we maybe flip a couple of these conditions and have them continue;
to reduce nesting?
Consider the following example:
A repo contains a
global.json
file requiring the .NET SDK version8.0.303
. A project in that repo has a dependency onSystem.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 toSystem.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:(Doing some manual checking, the version of
System.Text.Json
that the8.0.303
SDK is using as a replacement is8.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 SDK8.0.303
just so happens to match exactly with the NuGet packageSystem.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 version8.0.5
, we can correctly see that the dependency does exist as version8.0.4
so the update then to8.0.5
succeeds.This was accomplished by adding a submodule to the
dotnet/core
repo and parsing and correlating severalreleases.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 thatSystem.Text.Json.dll
was pulled out of the restore graph and it was replaced with one fromMicrosoft.NETCore.App.Ref/8.0.7
and that the corresponding version ofSystem.Text.Json
for that same runtime release was8.0.4
. This large mapping file is generated on build, so no manual steps need to be performed (and no huge file was added).