[Fixes #4555] Assemblies with a transitive dependency to MVC are not included as part of the list of discovered assemblies
This commit is contained in:
parent
b1054a28c7
commit
a490cf13a6
|
|
@ -63,14 +63,96 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
return Enumerable.Empty<RuntimeLibrary>();
|
||||
}
|
||||
|
||||
return dependencyContext.RuntimeLibraries.Where(IsCandidateLibrary);
|
||||
var candidatesResolver = new CandidateResolver(dependencyContext.RuntimeLibraries, ReferenceAssemblies);
|
||||
return candidatesResolver.GetCandidates();
|
||||
}
|
||||
|
||||
private static bool IsCandidateLibrary(RuntimeLibrary library)
|
||||
private class CandidateResolver
|
||||
{
|
||||
Debug.Assert(ReferenceAssemblies != null);
|
||||
return !ReferenceAssemblies.Contains(library.Name) &&
|
||||
library.Dependencies.Any(dependency => ReferenceAssemblies.Contains(dependency.Name));
|
||||
private readonly IDictionary<string, Dependency> _dependencies;
|
||||
|
||||
public CandidateResolver(IReadOnlyList<RuntimeLibrary> dependencies, ISet<string> referenceAssemblies)
|
||||
{
|
||||
_dependencies = dependencies
|
||||
.ToDictionary(d => d.Name, d => CreateDependency(d, referenceAssemblies));
|
||||
}
|
||||
|
||||
private Dependency CreateDependency(RuntimeLibrary library, ISet<string> referenceAssemblies)
|
||||
{
|
||||
var classification = DependencyClassification.Unknown;
|
||||
if (referenceAssemblies.Contains(library.Name))
|
||||
{
|
||||
classification = DependencyClassification.MvcReference;
|
||||
}
|
||||
|
||||
return new Dependency(library, classification);
|
||||
}
|
||||
|
||||
private DependencyClassification ComputeClassification(string dependency)
|
||||
{
|
||||
Debug.Assert(_dependencies.ContainsKey(dependency));
|
||||
|
||||
var candidateEntry = _dependencies[dependency];
|
||||
if (candidateEntry.Classification != DependencyClassification.Unknown)
|
||||
{
|
||||
return candidateEntry.Classification;
|
||||
}
|
||||
else
|
||||
{
|
||||
var classification = DependencyClassification.NotCandidate;
|
||||
foreach (var candidateDependency in candidateEntry.Library.Dependencies)
|
||||
{
|
||||
var dependencyClassification = ComputeClassification(candidateDependency.Name);
|
||||
if (dependencyClassification == DependencyClassification.Candidate ||
|
||||
dependencyClassification == DependencyClassification.MvcReference)
|
||||
{
|
||||
classification = DependencyClassification.Candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
candidateEntry.Classification = classification;
|
||||
|
||||
return classification;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<RuntimeLibrary> GetCandidates()
|
||||
{
|
||||
foreach (var dependency in _dependencies)
|
||||
{
|
||||
if (ComputeClassification(dependency.Key) == DependencyClassification.Candidate)
|
||||
{
|
||||
yield return dependency.Value.Library;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class Dependency
|
||||
{
|
||||
public Dependency(RuntimeLibrary library, DependencyClassification classification)
|
||||
{
|
||||
Library = library;
|
||||
Classification = classification;
|
||||
}
|
||||
|
||||
public RuntimeLibrary Library { get; }
|
||||
|
||||
public DependencyClassification Classification { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Library: {Library.Name}, Classification: {Classification}";
|
||||
}
|
||||
}
|
||||
|
||||
private enum DependencyClassification
|
||||
{
|
||||
Unknown = 0,
|
||||
Candidate = 1,
|
||||
NotCandidate = 2,
|
||||
MvcReference = 3
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,12 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
GetLibrary("Bar", "Microsoft.AspNetCore.Mvc"),
|
||||
GetLibrary("Qux", "Not.Mvc.Assembly", "Unofficial.Microsoft.AspNetCore.Mvc"),
|
||||
GetLibrary("Baz", "Microsoft.AspNetCore.Mvc.Abstractions"),
|
||||
GetLibrary("Microsoft.AspNetCore.Mvc.Core"),
|
||||
GetLibrary("Microsoft.AspNetCore.Mvc"),
|
||||
GetLibrary("Not.Mvc.Assembly"),
|
||||
GetLibrary("Unofficial.Microsoft.AspNetCore.Mvc"),
|
||||
GetLibrary("Microsoft.AspNetCore.Mvc.Abstractions"),
|
||||
|
||||
},
|
||||
Enumerable.Empty<RuntimeFallbacks>());
|
||||
|
||||
|
|
@ -73,6 +79,45 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
Assert.Equal(new[] { "Foo", "Bar", "Baz" }, candidates.Select(a => a.Name));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCandidateLibraries_ReturnsLibrariesWithTransitiveReferencesToAnyMvcAssembly()
|
||||
{
|
||||
// Arrange
|
||||
var expectedLibraries = new[] { "Foo", "Bar", "Baz", "LibraryA", "LibraryB", "LibraryC", "LibraryE", "LibraryG", "LibraryH" };
|
||||
|
||||
var dependencyContext = new DependencyContext(
|
||||
new TargetInfo("framework", "runtime", "signature", isPortable: true),
|
||||
CompilationOptions.Default,
|
||||
new CompilationLibrary[0],
|
||||
new[]
|
||||
{
|
||||
GetLibrary("Foo", "Bar"),
|
||||
GetLibrary("Bar", "Microsoft.AspNetCore.Mvc"),
|
||||
GetLibrary("Qux", "Not.Mvc.Assembly", "Unofficial.Microsoft.AspNetCore.Mvc"),
|
||||
GetLibrary("Baz", "Microsoft.AspNetCore.Mvc.Abstractions"),
|
||||
GetLibrary("Microsoft.AspNetCore.Mvc"),
|
||||
GetLibrary("Not.Mvc.Assembly"),
|
||||
GetLibrary("Microsoft.AspNetCore.Mvc.Abstractions"),
|
||||
GetLibrary("Unofficial.Microsoft.AspNetCore.Mvc"),
|
||||
GetLibrary("LibraryA", "LibraryB"),
|
||||
GetLibrary("LibraryB","LibraryC"),
|
||||
GetLibrary("LibraryC", "LibraryD", "Microsoft.AspNetCore.Mvc.Abstractions"),
|
||||
GetLibrary("LibraryD"),
|
||||
GetLibrary("LibraryE","LibraryF","LibraryG"),
|
||||
GetLibrary("LibraryF"),
|
||||
GetLibrary("LibraryG", "LibraryH"),
|
||||
GetLibrary("LibraryH", "LibraryI", "Microsoft.AspNetCore.Mvc"),
|
||||
GetLibrary("LibraryI")
|
||||
},
|
||||
Enumerable.Empty<RuntimeFallbacks>());
|
||||
|
||||
// Act
|
||||
var candidates = DefaultAssemblyPartDiscoveryProvider.GetCandidateLibraries(dependencyContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedLibraries, candidates.Select(a => a.Name));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetCandidateLibraries_SkipsMvcAssemblies()
|
||||
{
|
||||
|
|
@ -84,11 +129,13 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
new[]
|
||||
{
|
||||
GetLibrary("MvcSandbox", "Microsoft.AspNetCore.Mvc.Core", "Microsoft.AspNetCore.Mvc"),
|
||||
GetLibrary("Microsoft.AspNetCore.Mvc.TagHelpers", "Microsoft.AspNetCore.Mvc.Razor"),
|
||||
GetLibrary("Microsoft.AspNetCore.Mvc", "Microsoft.AspNetCore.Mvc.Abstractions", "Microsoft.AspNetCore.Mvc.Core"),
|
||||
GetLibrary("Microsoft.AspNetCore.Mvc.Core", "Microsoft.AspNetCore.HttpAbstractions"),
|
||||
GetLibrary("Microsoft.AspNetCore.HttpAbstractions"),
|
||||
GetLibrary("Microsoft.AspNetCore.Mvc", "Microsoft.AspNetCore.Mvc.Abstractions", "Microsoft.AspNetCore.Mvc.Core"),
|
||||
GetLibrary("Microsoft.AspNetCore.Mvc.Abstractions"),
|
||||
GetLibrary("Microsoft.AspNetCore.Mvc.TagHelpers", "Microsoft.AspNetCore.Mvc.Razor"),
|
||||
GetLibrary("Microsoft.AspNetCore.Mvc.Razor"),
|
||||
GetLibrary("ControllersAssembly", "Microsoft.AspNetCore.Mvc"),
|
||||
|
||||
},
|
||||
Enumerable.Empty<RuntimeFallbacks>());
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue