提交 6a14fe29 编写于 作者: J Jason Malinowski 提交者: GitHub

Merge pull request #21064 from jasonmalinowski/fix-lsl-handling-of-aliases

Correctly deduplicate metadata references for lightweight projects
......@@ -905,7 +905,8 @@ private void OutputListToOutputWindow(string prefix, IEnumerable<string> values)
}
}
var addedReferencePaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var metadataReferencesToAdd = new Dictionary<string, MetadataReferenceProperties>(StringComparer.OrdinalIgnoreCase);
foreach (var reference in metadataReferences)
{
var path = GetReferencePath(reference);
......@@ -916,10 +917,35 @@ private void OutputListToOutputWindow(string prefix, IEnumerable<string> values)
continue;
}
if (addedReferencePaths.Add(path))
if (metadataReferencesToAdd.TryGetValue(path, out var existingProperties))
{
projectContext.AddMetadataReference(path, reference.Properties);
// Merge existing aliases the properties that are already there
var allAliases = existingProperties.Aliases.AddRange(reference.Properties.Aliases);
// If one is empty and the other isn't, then we need to toss the global alias in too. The other cases
// are they're both empty (and this was a direct duplicate) or they're both non-empty and the merge
// is OK.
if ((existingProperties.Aliases.IsDefaultOrEmpty && !reference.Properties.Aliases.IsDefaultOrEmpty) ||
(!existingProperties.Aliases.IsDefaultOrEmpty && reference.Properties.Aliases.IsDefaultOrEmpty))
{
allAliases = allAliases.Add(MetadataReferenceProperties.GlobalAlias);
}
else
{
allAliases = allAliases.Distinct();
}
metadataReferencesToAdd[path] = existingProperties.WithAliases(allAliases);
}
else
{
metadataReferencesToAdd.Add(path, reference.Properties);
}
}
foreach (var metadataReferenceToAdd in metadataReferencesToAdd)
{
projectContext.AddMetadataReference(metadataReferenceToAdd.Key, metadataReferenceToAdd.Value);
}
var addedAnalyzerPaths = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册