Repository navigation
Conversation
|
|
||
| var items = _projectAdapter.GetBuildItemInformation(itemType, metadataNames); | ||
| var result = new List<IItem>(items is ICollection collection ? collection.Count : 0); | ||
| foreach (var (itemId, itemMetadata) in items) |
There was a problem hiding this comment.
Is this how it used to work? It seems better to make this wrap the original dictionary for lazy lookups rather than make a copy of the dictionary since not every metadata item is read?
There was a problem hiding this comment.
There's no "original" dictionary to wrap. We get an array of values, and need to use an array of names to understand which value matches what metadata.
Only PackageReference and ProjectReference get more than 1 metadata value.
Getting PackageVersion items and PrunePackageReference items use item.ItemMetadata.FirstOrDefault() to avoid needing look at keys to get the value.
Meanwhile, ProjectReference and PackageReference expose the two Array objects returned from the VS APIs, and then the callers use this helper method to first find the index in the metadata names array, then look up the value.
So, the existing code uses less memory, but does a linear search each lookup.
| return settings.GetConfigFilePaths(); | ||
| } | ||
|
|
||
|
|
jeffkl
left a comment
There was a problem hiding this comment.
There are compiler errors, I'm going to just leave this comment to see if I get notified when you push a fix...
|
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. |
Bug
working towards: NuGet/Home#14160
Description
Migrate non-SDK style projects in VS to use the same PackageSpecFactory as static graph restore (and eventually everything else), so we have less duplicated code.
Legacy csproj has some quirks, because of Visual Studio APIs. We read items via
IVsBuildItemStorage.FindItems, where it's necessary to pass it a list of item metadata that you're interested in. Therefore, at some point we need a complete list of metadata names per item type, which I added to LegacyProjectAdapter. In order to ensure this list is complete, I wrote a test that's rather long and seems complicated, but what it does is runsPackageSpecFactory.GetPackageSpecon a fake project adapter that ensures there's at least one item of every type (even types that we never expect in a non-SDK style project) and validates every metadata that PackageSpecFactory asks for is in the metadata names list. This way, if the metadata names dictionary is missing an item type, the test throws, or if the test didn't create at least one item of the type, the test throws, and finally if any of the item type metadata lists is missing a name, the test throws. This gives us confidence that the product code is not missing any metadata names.While working on this, I found that I didn't enable null checking on all PackageSpecFactory's interfaces, so I fixed that, which required some changes to null annotations to make right.
PR Checklist