diff --git a/src/Microsoft.AspNet.Mvc.Razor/Precompilation/RazorPreCompiler.cs b/src/Microsoft.AspNet.Mvc.Razor/Precompilation/RazorPreCompiler.cs index 02561e4b79..c13b06357b 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Precompilation/RazorPreCompiler.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Precompilation/RazorPreCompiler.cs @@ -26,15 +26,20 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation { public RazorPreCompiler( [NotNull] BeforeCompileContext compileContext, - [NotNull] IAssemblyLoadContextAccessor loadContextAccessor, + [NotNull] IAssemblyLoadContext loadContext, [NotNull] IFileProvider fileProvider, - [NotNull] IMemoryCache precompilationCache, - [NotNull] CompilationSettings compilationSettings) + [NotNull] IMemoryCache precompilationCache) { CompileContext = compileContext; - LoadContext = loadContextAccessor.GetLoadContext(GetType().GetTypeInfo().Assembly); + LoadContext = loadContext; FileProvider = fileProvider; - CompilationSettings = compilationSettings; + CompilationSettings = new CompilationSettings + { + CompilationOptions = compileContext.Compilation.Options, + // REVIEW: There should always be a syntax tree even if there are no files (we generate one) + Defines = compileContext.Compilation.SyntaxTrees[0].Options.PreprocessorSymbolNames, + LanguageVersion = compileContext.Compilation.LanguageVersion + }; PreCompilationCache = precompilationCache; TagHelperTypeResolver = new PrecompilationTagHelperTypeResolver(CompileContext, LoadContext); } diff --git a/src/Microsoft.AspNet.Mvc/RazorPreCompileModule.cs b/src/Microsoft.AspNet.Mvc/RazorPreCompileModule.cs index 5390e33c9c..9eb36f6f21 100644 --- a/src/Microsoft.AspNet.Mvc/RazorPreCompileModule.cs +++ b/src/Microsoft.AspNet.Mvc/RazorPreCompileModule.cs @@ -4,7 +4,6 @@ using System; using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Mvc.Razor.Precompilation; -using Microsoft.Dnx.Compilation; using Microsoft.Dnx.Compilation.CSharp; using Microsoft.Dnx.Runtime; using Microsoft.Framework.Caching.Memory; @@ -17,7 +16,7 @@ namespace Microsoft.AspNet.Mvc /// public abstract class RazorPreCompileModule : ICompileModule { - private readonly IServiceProvider _appServices; + private readonly IAssemblyLoadContext _loadContext; private readonly IMemoryCache _memoryCache; /// @@ -26,7 +25,7 @@ namespace Microsoft.AspNet.Mvc /// The for the application. public RazorPreCompileModule(IServiceProvider services) { - _appServices = services; + _loadContext = services.GetRequiredService(); // When CompactOnMemoryPressure is true, the MemoryCache evicts items at every gen2 collection. // In DTH, gen2 happens frequently enough to make it undesirable for caching precompilation results. We'll @@ -43,17 +42,13 @@ namespace Microsoft.AspNet.Mvc /// Pre-compiles all Razor views in the application. public virtual void BeforeCompile(BeforeCompileContext context) { - var compilerOptionsProvider = _appServices.GetRequiredService(); - var loadContextAccessor = _appServices.GetRequiredService(); - var compilationSettings = GetCompilationSettings(compilerOptionsProvider, context.ProjectContext); var fileProvider = new PhysicalFileProvider(context.ProjectContext.ProjectDirectory); var viewCompiler = new RazorPreCompiler( context, - loadContextAccessor, + _loadContext, fileProvider, - _memoryCache, - compilationSettings) + _memoryCache) { GenerateSymbols = GenerateSymbols }; @@ -65,15 +60,5 @@ namespace Microsoft.AspNet.Mvc public void AfterCompile(AfterCompileContext context) { } - - private static CompilationSettings GetCompilationSettings( - ICompilerOptionsProvider compilerOptionsProvider, - ProjectContext projectContext) - { - return compilerOptionsProvider.GetCompilerOptions(projectContext.Name, - projectContext.TargetFramework, - projectContext.Configuration) - .ToCompilationSettings(projectContext.TargetFramework); - } } }