Razor runtime compilation produces errors if running on a shared runtime that's rolled forward
Do not provide compilation references from runtime MVC assemblies. This avoids cases where the app is compiled against an older MVC but running against a newer one (e.g. shared fx roll forward) resulting in compiling against multiple versions of MVC assemblies Fixes #7969
This commit is contained in:
parent
224017c762
commit
7f2a64e32b
|
|
@ -2,6 +2,8 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
|
@ -59,15 +61,15 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
private static void AddDefaultFrameworkParts(ApplicationPartManager partManager)
|
||||
{
|
||||
var mvcTagHelpersAssembly = typeof(InputTagHelper).GetTypeInfo().Assembly;
|
||||
if(!partManager.ApplicationParts.OfType<AssemblyPart>().Any(p => p.Assembly == mvcTagHelpersAssembly))
|
||||
if (!partManager.ApplicationParts.OfType<AssemblyPart>().Any(p => p.Assembly == mvcTagHelpersAssembly))
|
||||
{
|
||||
partManager.ApplicationParts.Add(new AssemblyPart(mvcTagHelpersAssembly));
|
||||
partManager.ApplicationParts.Add(new FrameworkAssemblyPart(mvcTagHelpersAssembly));
|
||||
}
|
||||
|
||||
|
||||
var mvcRazorAssembly = typeof(UrlResolutionTagHelper).GetTypeInfo().Assembly;
|
||||
if(!partManager.ApplicationParts.OfType<AssemblyPart>().Any(p => p.Assembly == mvcRazorAssembly))
|
||||
if (!partManager.ApplicationParts.OfType<AssemblyPart>().Any(p => p.Assembly == mvcRazorAssembly))
|
||||
{
|
||||
partManager.ApplicationParts.Add(new AssemblyPart(mvcRazorAssembly));
|
||||
partManager.ApplicationParts.Add(new FrameworkAssemblyPart(mvcRazorAssembly));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -94,5 +96,16 @@ namespace Microsoft.Extensions.DependencyInjection
|
|||
|
||||
return builder;
|
||||
}
|
||||
|
||||
[DebuggerDisplay("{Name}")]
|
||||
private class FrameworkAssemblyPart : AssemblyPart, ICompilationReferencesProvider
|
||||
{
|
||||
public FrameworkAssemblyPart(Assembly assembly)
|
||||
: base(assembly)
|
||||
{
|
||||
}
|
||||
|
||||
IEnumerable<string> ICompilationReferencesProvider.GetReferencePaths() => Enumerable.Empty<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ namespace BasicWebSite.Controllers
|
|||
// Ensures that the entry assembly part is marked correctly.
|
||||
var assemblyPartMetadata = applicationPartManager
|
||||
.ApplicationParts
|
||||
.Where(part => part.GetType() == typeof(AssemblyPart))
|
||||
.OfType<AssemblyPart>()
|
||||
.Select(part => part.Name)
|
||||
.ToArray();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue