Skip to content

Fix issue casing issue with GeneratePathProperty - #2746

Merged
nkolev92 merged 2 commits into
NuGet:devfrom
jeffkl:fix-generatepathproperty-case-issue
Mar 14, 2019
Merged

nkolev92 merged 2 commits into
NuGet:devfrom
jeffkl:fix-generatepathproperty-case-issue

Conversation

@jeffkl

@jeffkl jeffkl commented Mar 1, 2019

Copy link
Copy Markdown
Contributor

Bug

Fixes: NuGet/Home#7843
Regression: No

Fix

Details: Use a case insenstive HashSet<string> instead of an IEnumerable<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

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

@nkolev92 nkolev92 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

thanks @jeffkl


// 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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you consider making packagesWithTools case insensitive at line 429? That would avoid allocating another collection.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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 ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was assuming that NuGet would always want to treat any collection with packageId keys as case insensitive, but I could be wrong.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@nkolev92
nkolev92 merged commit 458908c into NuGet:dev Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants