Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 485e6e5

Browse files
committed
React to dnx refactoring changes
- Use compilation options from the Compilation itself - Get the parse options from the first syntax tree - Get the build time IAssemblyLoadContext directly
1 parent a0879cc commit 485e6e5

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

src/Microsoft.AspNet.Mvc.Razor/Precompilation/RazorPreCompiler.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,20 @@ public class RazorPreCompiler
2626
{
2727
public RazorPreCompiler(
2828
[NotNull] BeforeCompileContext compileContext,
29-
[NotNull] IAssemblyLoadContextAccessor loadContextAccessor,
29+
[NotNull] IAssemblyLoadContext loadContext,
3030
[NotNull] IFileProvider fileProvider,
31-
[NotNull] IMemoryCache precompilationCache,
32-
[NotNull] CompilationSettings compilationSettings)
31+
[NotNull] IMemoryCache precompilationCache)
3332
{
3433
CompileContext = compileContext;
35-
LoadContext = loadContextAccessor.GetLoadContext(GetType().GetTypeInfo().Assembly);
34+
LoadContext = loadContext;
3635
FileProvider = fileProvider;
37-
CompilationSettings = compilationSettings;
36+
CompilationSettings = new CompilationSettings
37+
{
38+
CompilationOptions = compileContext.Compilation.Options,
39+
// REVIEW: There should always be a syntax tree even if there are no files (we generate one)
40+
Defines = compileContext.Compilation.SyntaxTrees[0].Options.PreprocessorSymbolNames,
41+
LanguageVersion = compileContext.Compilation.LanguageVersion
42+
};
3843
PreCompilationCache = precompilationCache;
3944
TagHelperTypeResolver = new PrecompilationTagHelperTypeResolver(CompileContext, LoadContext);
4045
}

src/Microsoft.AspNet.Mvc/RazorPreCompileModule.cs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using Microsoft.AspNet.FileProviders;
66
using Microsoft.AspNet.Mvc.Razor.Precompilation;
7-
using Microsoft.Dnx.Compilation;
87
using Microsoft.Dnx.Compilation.CSharp;
98
using Microsoft.Dnx.Runtime;
109
using Microsoft.Framework.Caching.Memory;
@@ -17,7 +16,7 @@ namespace Microsoft.AspNet.Mvc
1716
/// </summary>
1817
public abstract class RazorPreCompileModule : ICompileModule
1918
{
20-
private readonly IServiceProvider _appServices;
19+
private readonly IAssemblyLoadContext _loadContext;
2120
private readonly IMemoryCache _memoryCache;
2221

2322
/// <summary>
@@ -26,7 +25,7 @@ public abstract class RazorPreCompileModule : ICompileModule
2625
/// <param name="services">The <see cref="IServiceProvider"/> for the application.</param>
2726
public RazorPreCompileModule(IServiceProvider services)
2827
{
29-
_appServices = services;
28+
_loadContext = services.GetRequiredService<IAssemblyLoadContext>();
3029

3130
// When CompactOnMemoryPressure is true, the MemoryCache evicts items at every gen2 collection.
3231
// In DTH, gen2 happens frequently enough to make it undesirable for caching precompilation results. We'll
@@ -43,17 +42,13 @@ public RazorPreCompileModule(IServiceProvider services)
4342
/// <remarks>Pre-compiles all Razor views in the application.</remarks>
4443
public virtual void BeforeCompile(BeforeCompileContext context)
4544
{
46-
var compilerOptionsProvider = _appServices.GetRequiredService<ICompilerOptionsProvider>();
47-
var loadContextAccessor = _appServices.GetRequiredService<IAssemblyLoadContextAccessor>();
48-
var compilationSettings = GetCompilationSettings(compilerOptionsProvider, context.ProjectContext);
4945
var fileProvider = new PhysicalFileProvider(context.ProjectContext.ProjectDirectory);
5046

5147
var viewCompiler = new RazorPreCompiler(
5248
context,
53-
loadContextAccessor,
49+
_loadContext,
5450
fileProvider,
55-
_memoryCache,
56-
compilationSettings)
51+
_memoryCache)
5752
{
5853
GenerateSymbols = GenerateSymbols
5954
};
@@ -65,15 +60,5 @@ public virtual void BeforeCompile(BeforeCompileContext context)
6560
public void AfterCompile(AfterCompileContext context)
6661
{
6762
}
68-
69-
private static CompilationSettings GetCompilationSettings(
70-
ICompilerOptionsProvider compilerOptionsProvider,
71-
ProjectContext projectContext)
72-
{
73-
return compilerOptionsProvider.GetCompilerOptions(projectContext.Name,
74-
projectContext.TargetFramework,
75-
projectContext.Configuration)
76-
.ToCompilationSettings(projectContext.TargetFramework);
77-
}
7863
}
7964
}

0 commit comments

Comments
 (0)