parent
140c8686b5
commit
756953fd50
|
|
@ -17,6 +17,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class DefaultAssemblyProvider : IAssemblyProvider
|
public class DefaultAssemblyProvider : IAssemblyProvider
|
||||||
{
|
{
|
||||||
|
private readonly Assembly _entryAssembly;
|
||||||
private readonly DependencyContext _dependencyContext;
|
private readonly DependencyContext _dependencyContext;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -25,8 +26,8 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
/// <param name="environment">The <see cref="IApplicationEnvironment"/>.</param>
|
/// <param name="environment">The <see cref="IApplicationEnvironment"/>.</param>
|
||||||
public DefaultAssemblyProvider(IApplicationEnvironment environment)
|
public DefaultAssemblyProvider(IApplicationEnvironment environment)
|
||||||
{
|
{
|
||||||
var applicationAssembly = Assembly.Load(new AssemblyName(environment.ApplicationName));
|
_entryAssembly = Assembly.Load(new AssemblyName(environment.ApplicationName));
|
||||||
_dependencyContext = DependencyContext.Load(applicationAssembly);
|
_dependencyContext = DependencyContext.Load(_entryAssembly);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -59,6 +60,12 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
if (_dependencyContext == null)
|
||||||
|
{
|
||||||
|
// Use the entry assembly as the sole candidate.
|
||||||
|
return new[] { _entryAssembly };
|
||||||
|
}
|
||||||
|
|
||||||
return GetCandidateLibraries()
|
return GetCandidateLibraries()
|
||||||
.SelectMany(l => l.Assemblies)
|
.SelectMany(l => l.Assemblies)
|
||||||
.Select(Load);
|
.Select(Load);
|
||||||
|
|
@ -78,7 +85,7 @@ namespace Microsoft.AspNetCore.Mvc.Infrastructure
|
||||||
return Enumerable.Empty<RuntimeLibrary>();
|
return Enumerable.Empty<RuntimeLibrary>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return DependencyContext.Default.RuntimeLibraries.Where(IsCandidateLibrary);
|
return _dependencyContext.RuntimeLibraries.Where(IsCandidateLibrary);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Assembly Load(RuntimeAssembly assembly)
|
private static Assembly Load(RuntimeAssembly assembly)
|
||||||
|
|
|
||||||
|
|
@ -243,6 +243,12 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Internal
|
||||||
|
|
||||||
private List<MetadataReference> GetApplicationReferences()
|
private List<MetadataReference> GetApplicationReferences()
|
||||||
{
|
{
|
||||||
|
if (_dependencyContext == null)
|
||||||
|
{
|
||||||
|
// Avoid null ref if the entry point does not have DependencyContext specified.
|
||||||
|
return new List<MetadataReference>();
|
||||||
|
}
|
||||||
|
|
||||||
return _dependencyContext.CompileLibraries
|
return _dependencyContext.CompileLibraries
|
||||||
.SelectMany(library => library.ResolveReferencePaths())
|
.SelectMany(library => library.ResolveReferencePaths())
|
||||||
.Select(CreateMetadataFileReference)
|
.Select(CreateMetadataFileReference)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue