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

Make PackageSpecDependencyProvider consider the version being requested #5452

Closed
wants to merge 6 commits into from

Conversation

nkolev92
Copy link
Member

@nkolev92 nkolev92 commented Oct 2, 2023

Bug

Fixes: NuGet/Home#10368

Regression? Last working version:

Description

Replacement for #5397.
Projects are expected to be preferred over packages, but only when the version matches. Note that project version does that

var packageVersion = packageVersions?.FindBestMatch(libraryRange.VersionRange, version => version);
if (packageVersion != null)
{
return new LibraryIdentity
{
Name = libraryRange.Name,
Version = packageVersion,
Type = LibraryType.Package
};
}
.

If this is not done, then projects may be selected in frameworks in which the project was never referenced.

More details in #5397 (comment).

Note that the test in question validates the scenario the runtime team is experiencing.

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@nkolev92 nkolev92 marked this pull request as ready for review October 3, 2023 00:04
@nkolev92 nkolev92 requested a review from a team as a code owner October 3, 2023 00:04
jeffkl
jeffkl previously approved these changes Oct 3, 2023
@jeffkl jeffkl requested a review from a team October 3, 2023 17:38
@nkolev92
Copy link
Member Author

nkolev92 commented Oct 3, 2023

cc @ViktorHofer

Copy link
Contributor

@donnie-msft donnie-msft left a comment

Choose a reason for hiding this comment

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

Not sure if the null version range could be a breaking change?

@@ -86,7 +86,15 @@ public Library GetLibrary(LibraryRange libraryRange, NuGetFramework targetFramew
// This must exist in the external references
if (_externalProjectsByUniqueName.TryGetValue(name, out ExternalProjectReference externalReference))
{
packageSpec = externalReference.PackageSpec;
if (externalReference.PackageSpec == null ||
libraryRange.VersionRange.FindBestMatch(new NuGetVersion[] { externalReference.PackageSpec.Version }) != null)
Copy link
Contributor

Choose a reason for hiding this comment

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

VersionRange can be null to represent "all versions".

Suggested change
libraryRange.VersionRange.FindBestMatch(new NuGetVersion[] { externalReference.PackageSpec.Version }) != null)
libraryRange.VersionRange?.FindBestMatch(new NuGetVersion[] { externalReference.PackageSpec.Version }) != null)

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'm not sure how this should work yet.
It's pretty surprising to me that we've gotten no null refs in the tests.

Copy link
Member

Choose a reason for hiding this comment

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

Projects are expected to be preferred over packages, but only when the version matches

Why's that? It's not intuitive to me.

I really liked the project.json feature, from .NET Core 1.0 pre-release days, where you could add a package's project to the build, via global.json, and then it would use the project rather than the package. I thought it was regardless of version. This makes it much easier to debug and develop a package which has a bug in another project in a different repo.

Although perhaps this is straying too far from the linked bug and is a different feature request instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

The version check allows you to be able to explicitly depend on a package if you choose to.
Now it'd replace package with project every single time.

There's obviously a lot of feature options here, like for example, being able to control whether project o package replacement is allowed.

@ghost ghost added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Oct 20, 2023
@ghost
Copy link

ghost commented Oct 20, 2023

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

@ViktorHofer
Copy link
Contributor

@nkolev92 please re-open this PR

@ghost ghost removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Nov 3, 2023
@jeffkl jeffkl reopened this Nov 3, 2023
@jeffkl jeffkl self-requested a review November 3, 2023 17:02
@nkolev92
Copy link
Member Author

nkolev92 commented Nov 3, 2023

Thanks for reopening @jeffkl.

@ViktorHofer I'll get to this soon.

@jeffkl jeffkl marked this pull request as draft November 7, 2023 18:18
@ghost ghost added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Nov 14, 2023
@ghost
Copy link

ghost commented Nov 14, 2023

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

@ghost ghost closed this Nov 21, 2023
@nkolev92 nkolev92 deleted the dev-nkolev92-10368 branch November 21, 2023 21:00
@nkolev92 nkolev92 restored the dev-nkolev92-10368 branch November 21, 2023 21:00
@nkolev92 nkolev92 reopened this Nov 21, 2023
@ghost ghost removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Nov 21, 2023
@ghost ghost added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Nov 28, 2023
@ghost
Copy link

ghost commented Nov 28, 2023

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

@ghost ghost closed this Dec 6, 2023
@ViktorHofer
Copy link
Contributor

@nkolev92 we would really like to consume this bugfix in runtime as part of upgrading to a nightly 9.0 SDK / Preview 1. I don't think there's much left here, right?

@ghost ghost removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Dec 6, 2023
@ViktorHofer
Copy link
Contributor

ping @nkolev92, we really need to get this into the .NET 9 Preview 1 for runtime to be able to use ProjectReferences correctly with the new SDK bump. We have been waiting for this for months without a clear indication what was missing / no progress. Please re-open the PR. cc @ericstj

@nkolev92 nkolev92 reopened this Jan 8, 2024
@ghost
Copy link

ghost commented Jan 15, 2024

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

@ghost ghost added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Jan 15, 2024
@ghost ghost closed this Jan 22, 2024
@nkolev92 nkolev92 deleted the dev-nkolev92-10368 branch July 12, 2024 18:59
ViktorHofer added a commit to ViktorHofer/NuGet.Client that referenced this pull request Aug 21, 2024
Fixes: NuGet/Home#10368
Re-submit of NuGet#5452

NuGet gets confused with transitive project and package
dependencies with the same identity (name) in a multi-targeting project
and selects the wrong type (project instead of package).

Projects are expected to be preferred over packages, but only when the
version matches. If the version doesn't match, projects shouldn't be
selected in frameworks which don't declare a ProjectReference to those
projects.
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed
Projects
None yet
6 participants