From c66c408c1504c6af7e6b0a89c13691df7f733928 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Sun, 3 Apr 2016 14:49:09 -0700 Subject: [PATCH] DefaultAssemblyPartDiscoveryProvider.IsCandidateLibrary should not look at types in Mvc assemblies Fixes #4363 --- .../DefaultAssemblyPartDiscoveryProvider.cs | 3 ++- ...efaultAssemblyPartDiscoveryProviderTest.cs | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultAssemblyPartDiscoveryProvider.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultAssemblyPartDiscoveryProvider.cs index bfe682e881..11d755086f 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultAssemblyPartDiscoveryProvider.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/DefaultAssemblyPartDiscoveryProvider.cs @@ -69,7 +69,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal private static bool IsCandidateLibrary(RuntimeLibrary library) { Debug.Assert(ReferenceAssemblies != null); - return library.Dependencies.Any(dependency => ReferenceAssemblies.Contains(dependency.Name)); + return !ReferenceAssemblies.Contains(library.Name) && + library.Dependencies.Any(dependency => ReferenceAssemblies.Contains(dependency.Name)); } } } diff --git a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/DefaultAssemblyPartDiscoveryProviderTest.cs b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/DefaultAssemblyPartDiscoveryProviderTest.cs index 9179a3cd2d..c63d621448 100644 --- a/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/DefaultAssemblyPartDiscoveryProviderTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/DefaultAssemblyPartDiscoveryProviderTest.cs @@ -73,6 +73,32 @@ namespace Microsoft.AspNetCore.Mvc.Internal Assert.Equal(new[] { "Foo", "Bar", "Baz" }, candidates.Select(a => a.Name)); } + [Fact] + public void GetCandidateLibraries_SkipsMvcAssemblies() + { + // Arrange + var dependencyContext = new DependencyContext( + new TargetInfo("framework", "runtime", "signature", isPortable: true), + CompilationOptions.Default, + new CompilationLibrary[0], + 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("ControllersAssembly", "Microsoft.AspNetCore.Mvc"), + + }, + Enumerable.Empty()); + + // Act + var candidates = DefaultAssemblyPartDiscoveryProvider.GetCandidateLibraries(dependencyContext); + + // Assert + Assert.Equal(new[] { "MvcSandbox", "ControllersAssembly" }, candidates.Select(a => a.Name)); + } + // This test verifies DefaultAssemblyPartDiscoveryProvider.ReferenceAssemblies reflects the actual loadable assemblies // of the libraries that Microsoft.AspNetCore.Mvc dependes on. // If we add or remove dependencies, this test should be changed together.