Repository navigation
Handle when same name and same version both project and package are referenced in solution - #3789
Conversation
|
This would be great to have a better error message/handling of this, I just hit it and it took me a while to figure out what was going on. Cheers! |
f00e077 to
4ded836
Compare
|
@NuGet/nuget-client Also I investigated issue#10368 related this but it requires design change, and ROI is very small since it's just uncommon edge case. So want to keep fix as it's. I'm working on adding unit test. |
Imo, not as part of this change. That's not something we want to introduce at this point as no one is really asking for it. |
|
@NuGet/nuget-client |
2d25ac1 to
6376f86
Compare
|
Can you please:
|
Can you check now? Now I more toward to show warning/error direction instead of solve problem by choose one over other (project vs package). By showing clear warning/error we make user take a action to solve problem for good. |
Project was preferred over Package, but not in all scenarios. Fixing this bug just establishes the already known expectation. |
Can you recommend next course of action? Is my current fix I submitted ok for bug fix? Do I need to change anything? |
|
I think the first idea of continuing to choosing project over package is more appropriate. Especially because that matches current behavior. I'll review the code later. |
@nkolev92 |
|
@erdembayar Sorry, this slipped through my fingers last week. I've added it to my queue. |
|
Reviewing your description, I think proposal 1 makes sense. a. We should file an issue for that. Start it in our repo. The fix might actually end up being on project-system side, but it's NUGet scenario. It sounds to me like this is what you implemented, so I'll review the code. |
| var first = item.First(); | ||
| var second = item.Last(); | ||
|
|
||
| if (first.Type == second.Type) |
There was a problem hiding this comment.
Not really, I tried to be more cautious, now removing.
erdembayar
left a comment
There was a problem hiding this comment.
@nkolev92
Thank you for your review.
I addressed your PR comments, please check.
| var first = item.First(); | ||
| var second = item.Last(); | ||
|
|
||
| if (first.Type == second.Type) |
There was a problem hiding this comment.
Not really, I tried to be more cautious, now removing.
|
@nkolev92 |
7aca23e to
c6b33b9
Compare
c6b33b9 to
ff603ef
Compare
a2e1dec to
68b2f07
Compare
|
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. |
|
uhh this probably shouldn't be auto closed, lol |
|
@nkolev92 Code used for benchmarking is here.
[Host] : .NET 5.0.7 (5.0.721.25508), X64 RyuJIT
.NET SDK=6.0.100-preview.5.21302.13
|
|
|
||
| private void ValidateLockFileLibrary(IList<LockFileLibrary> libraries) | ||
| { | ||
| var libNameVersion = libraries.Select(l => l.Name + " " + l.Version); |
There was a problem hiding this comment.
Would it be at all simpler to just create a dictionary, and iterate over the libs one by one and updating the selected ref as we go?
Currently
-
Distinct uses a set internally - 1 pass: https://github.com/dotnet/runtime/blob/57bfe474518ab5b7cfe6bf7424a79ce3af9d6657/src/libraries/System.Linq/src/System/Linq/Distinct.cs.
-
The ToLookup statement creates a dict and then it iterates over that, allocating a list there.
-
Finally, iterate over the main list to remove the dups.
All of that can be replaced with 1 dictionary and 1 loop.
The moment you find a conflict, rank references and dedup.
Same applies to both methods.
There was a problem hiding this comment.
@nkolev92
Could you be able to check now? I pushed new changes.
Bug
Fixes: Issue#6795
Regression: No
Fix
Details: The problem occurs project and package with same name and same version referenced directly and transitively to project. Let's call them "DoublyReferenced" for both project and package and with version is "1.0.0"
Then it fails with vague error "" in VS:
Even on cli with dotnet.exe it fails with another vague error, actually it's telling duplicate same name keys are created and we have conflict.

Currently below scenario works, after examination it actual doesn't create key duplicate key as our case, only one key for project created due to project over package preference. It looks very similar to our case in question but actually it's not.
Even it works it cause squiggly yellow warning with Roslyn.

There're only 2 solutions to this problem.
Still this one have issues:
a. Above Roslyn warning keep continue to show up with or without this fix until we remove one of them.
b. Project reference always winner, it's implicit to user and maybe it's not user actually wanted, maybe yes. All different combinations of direct and transient references works except below 1 case.

c. If package direct reference and project is transitive reference then VS doesn't even compile
Maybe this one is most clean and confusion free solution. I can change to implementation, please just give me your feedback.
Also in this case do we need to introduce new warning NUxxxx code?
Testing/Validation
Tests Added: Yes
Reason for not adding tests:
Validation: