Skip to content

Skip package when resolving package dependencies if it appears multiple times #30105

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

Closed
wants to merge 1 commit into from

Conversation

smitpatel
Copy link

Resolves dotnet/NuGet.BuildTasks#86

NuGet shows error about conflict already so we just skip it

…le times

Resolves dotnet/NuGet.BuildTasks#86

NuGet shows error about conflict already so we just skip it
@ghost ghost added the Area-ReadyToRun label Jan 24, 2023
@smitpatel smitpatel requested a review from dsplaisted January 24, 2023 21:57
resolvedPackageVersions.Remove(libraryName);
}

resolvedPackageVersions[libraryName] = library.Version.ToNormalizedString();
Copy link
Author

Choose a reason for hiding this comment

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

If we let first one pass-through then we can avoid hashset lookup & dict.Remove calls.
If we want to minimize the impact then perhaps try/catch could be useful so we only run additional code only in error case.

string libraryName = library.Name;
if (duplicatedPackages.Contains(libraryName))
{
continue;
Copy link
Member

Choose a reason for hiding this comment

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

Add some logging so that i.e. a binlog shows that duplicate packages are consumed?

Copy link
Author

Choose a reason for hiding this comment

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

Can you point me to some example of logging, that would be helpful.

{
duplicatedPackages.Add(libraryName);
resolvedPackageVersions.Remove(libraryName);
}
Copy link
Member

Choose a reason for hiding this comment

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

might be better with an else here as you can then avoid having to remove every time

foreach (LockFileTargetLibrary library in target.Libraries)
{
string libraryName = library.Name;
if (duplicatedPackages.Contains(libraryName))
Copy link
Member

Choose a reason for hiding this comment

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

If we only use the duplicatedPackages HashSet here, is it worth the perf hit of even having it. You could just have the below as it simplifies the code (unless the hashset check is so much faster than the dictionary containsKey check that it's worth it)

  if (!resolvedPackageVersions.ContainsKey(libraryName))
                {
resolvedPackageVersions[libraryName] = library.Version.ToNormalizedString();
                }

Copy link
Author

Choose a reason for hiding this comment

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

If we use this, then first package of duplicate packages will get added to the dictionary. Current code avoids adding any duplicate packages to dictionary. Happy to take whichever path you like. Letting the first one pass through certainly has better perf.

@smitpatel
Copy link
Author

@dsplaisted - Can you also take a look at this?

@dsplaisted
Copy link
Member

While looking at this, I remembered that as of #28405, we don't run the ResolvePackageDependencies task at all by default anymore. That logic has moved to ResolvePackageAssets. So this is probably not necessary anymore. It would be good to try to repro the issue and see if it still repros on 7.0.200.

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

Successfully merging this pull request may close these issues.

The "ResolvePackageDependencies" task failed unexpectedly - An item with the same key has already been added
4 participants