提交 f85b53ea 编写于 作者: M Manish Vasani

Merge pull request #5591 from mavasani/Issue3020

Fix the AnalyzerDependencyChecker to ignore mscorlib
......@@ -22,6 +22,7 @@ internal sealed class AnalyzerDependencyCheckingService
private static readonly object s_dependencyConflictErrorId = new object();
private static readonly IIgnorableAssemblyList s_systemPrefixList = new IgnorableAssemblyNamePrefixList("System");
private static readonly IIgnorableAssemblyList s_explicitlyIgnoredAssemblyList = new IgnorableAssemblyIdentityList(GetExplicitlyIgnoredAssemblyIdentities());
private static readonly IIgnorableAssemblyList s_assembliesIgnoredByNameList = new IgnorableAssemblyNameList(ImmutableHashSet.Create("mscorlib"));
private readonly VisualStudioWorkspaceImpl _workspace;
private readonly HostDiagnosticUpdateSource _updateSource;
......@@ -195,7 +196,7 @@ private Task<AnalyzerDependencyResults> GetConflictsAsync()
IEnumerable<AssemblyIdentity> loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().Select(assembly => AssemblyIdentity.FromAssemblyDefinition(assembly));
IgnorableAssemblyIdentityList loadedAssembliesList = new IgnorableAssemblyIdentityList(loadedAssemblies);
IIgnorableAssemblyList[] ignorableAssemblyLists = new[] { s_systemPrefixList, s_explicitlyIgnoredAssemblyList, loadedAssembliesList };
IIgnorableAssemblyList[] ignorableAssemblyLists = new[] { s_systemPrefixList, s_explicitlyIgnoredAssemblyList, s_assembliesIgnoredByNameList, loadedAssembliesList };
return new AnalyzerDependencyChecker(currentAnalyzerPaths, ignorableAssemblyLists, _bindingRedirectionService).Run(_cancellationTokenSource.Token);
},
TaskScheduler.Default);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Diagnostics;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
namespace Microsoft.VisualStudio.LanguageServices.Implementation
{
internal sealed class IgnorableAssemblyNameList : IIgnorableAssemblyList
{
private readonly ImmutableHashSet<string> _assemblyNamesToIgnore;
public IgnorableAssemblyNameList(ImmutableHashSet<string> assemblyNamesToIgnore)
{
Debug.Assert(assemblyNamesToIgnore != null);
_assemblyNamesToIgnore = assemblyNamesToIgnore;
}
public bool Includes(AssemblyIdentity assemblyIdentity)
{
return _assemblyNamesToIgnore.Contains(assemblyIdentity.Name);
}
}
}
......@@ -36,6 +36,7 @@
<Compile Include="Implementation\AnalyzerDependency\AnalyzerDependencyCheckingService.cs" />
<Compile Include="Implementation\AnalyzerDependency\AnalyzerDependencyConflict.cs" />
<Compile Include="Implementation\AnalyzerDependency\IgnorableAssemblyIdentityList.cs" />
<Compile Include="Implementation\AnalyzerDependency\IgnorableAssemblyNameList.cs" />
<Compile Include="Implementation\AnalyzerDependency\IgnorableAssemblyNamePrefixList.cs" />
<Compile Include="Implementation\CompilationErrorTelemetry\CompilationErrorTelemetryIncrementalAnalyzer.cs" />
<Compile Include="Implementation\Diagnostics\VisualStudioVenusSpanMappingService.cs" />
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Immutable
Imports System.IO
Imports System.Text
Imports Microsoft.CodeAnalysis
......@@ -832,6 +833,49 @@ public class A
Assert.False(ignorableAssemblyList.Includes(alpha))
End Sub
<Fact, WorkItem(3020, "https://github.com/dotnet/roslyn/issues/3020")>
Public Sub IgnorableAssemblyNameList_IncludesItem_Prefix()
Dim ignorableAssemblyList = New IgnorableAssemblyNameList(ImmutableHashSet.Create("Alpha"))
Dim alphaBeta As AssemblyIdentity = Nothing
AssemblyIdentity.TryParseDisplayName("Alpha.Beta, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", alphaBeta)
Assert.False(ignorableAssemblyList.Includes(alphaBeta))
End Sub
<Fact, WorkItem(3020, "https://github.com/dotnet/roslyn/issues/3020")>
Public Sub IgnorableAssemblyNameList_IncludesItem_WholeName()
Dim ignorableAssemblyList = New IgnorableAssemblyNameList(ImmutableHashSet.Create("Alpha"))
' No version
Dim alpha As AssemblyIdentity = Nothing
AssemblyIdentity.TryParseDisplayName("Alpha", alpha)
Assert.True(ignorableAssemblyList.Includes(alpha))
' With a version.
alpha = Nothing
AssemblyIdentity.TryParseDisplayName("Alpha, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", alpha)
Assert.True(ignorableAssemblyList.Includes(alpha))
' Version doesn't matter.
alpha = Nothing
AssemblyIdentity.TryParseDisplayName("Alpha, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", alpha)
Assert.True(ignorableAssemblyList.Includes(alpha))
End Sub
<Fact, WorkItem(3020, "https://github.com/dotnet/roslyn/issues/3020")>
Public Sub IgnorableAssemblyNameList_DoesNotIncludeItem()
Dim ignorableAssemblyList = New IgnorableAssemblyNameList(ImmutableHashSet.Create("Beta"))
Dim alpha As AssemblyIdentity = Nothing
AssemblyIdentity.TryParseDisplayName("Alpha, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", alpha)
Assert.False(ignorableAssemblyList.Includes(alpha))
End Sub
Private Function BuildLibrary(directory As DisposableDirectory, fileContents As String, libraryName As String, ParamArray referenceNames As String()) As String
Dim sourceFile = directory.CreateFile(libraryName + ".cs").WriteAllText(fileContents).Path
Dim tempOut = Path.Combine(directory.Path, libraryName + ".out")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册