Repository navigation
Fix issue casing issue with GeneratePathProperty - #2746
Conversation
Use a case insenstive HashSet instead of an IEnumerable<string>. This removes the need to change the case comparison and should improve performance. Also updated unit test
|
|
||
| // Distinct union of tool packages and packages with GeneratePathProperty=true | ||
| var packageIdsToCreatePropertiesFor = packagesWithTools.Union(projectGraph.Item.Data.Dependencies.Where(i => i.GeneratePathProperty).Select(i => i.Name)).Distinct(StringComparer.OrdinalIgnoreCase); | ||
| var packageIdsToCreatePropertiesFor = new HashSet<string>(packagesWithTools.Union(projectGraph.Item.Data.Dependencies.Where(i => i.GeneratePathProperty).Select(i => i.Name)), StringComparer.OrdinalIgnoreCase); |
There was a problem hiding this comment.
Did you consider making packagesWithTools case insensitive at line 429? That would avoid allocating another collection.
There was a problem hiding this comment.
I have to allocate twice because you could have only wanted a property for a package for a particular TFM.
<ItemGroup>
<PackageReference Include="Foo"
Version="1.0"
GeneratePathProperty="true"
Condition="'$(TargetFramework)' == 'net46'" />
<PackageReference Include="Foo"
Version="1.0"
Condition="'$(TargetFramework)' != 'net46'" />
</ItemGroup>The second HashSet<T> is inside the foreach loop. Is that right @nkolev92 ?
There was a problem hiding this comment.
I was assuming that NuGet would always want to treat any collection with packageId keys as case insensitive, but I could be wrong.
There was a problem hiding this comment.
In my latest commit I'm using two different collections. So packages with a tools folder get a property regardless of TFM and then a collection is allocated for each TFM for packages with GeneratePathProperty. Both collections are case-insensitive.
…eneratePathProperty set to true
Bug
Fixes: NuGet/Home#7843
Regression: No
Fix
Details: Use a case insenstive
HashSet<string>instead of anIEnumerable<string>. This removes the need to change the case comparison and should improve performance. I didn't catch the fact that the Linq query was being executed a lot of times.Testing/Validation
Tests Added: Yes