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

Commit

Permalink
React to dnx refactoring changes
Browse files Browse the repository at this point in the history
- Use compilation options from the Compilation itself
- Get the parse options from the first syntax tree
- Get the build time IAssemblyLoadContext directly
  • Loading branch information
davidfowl committed Aug 19, 2015
1 parent a0879cc commit 485e6e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
15 changes: 10 additions & 5 deletions src/Microsoft.AspNet.Mvc.Razor/Precompilation/RazorPreCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@ public class RazorPreCompiler
{
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);
}
Expand Down
23 changes: 4 additions & 19 deletions src/Microsoft.AspNet.Mvc/RazorPreCompileModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,7 +16,7 @@ namespace Microsoft.AspNet.Mvc
/// </summary>
public abstract class RazorPreCompileModule : ICompileModule
{
private readonly IServiceProvider _appServices;
private readonly IAssemblyLoadContext _loadContext;
private readonly IMemoryCache _memoryCache;

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

// 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
Expand All @@ -43,17 +42,13 @@ public RazorPreCompileModule(IServiceProvider services)
/// <remarks>Pre-compiles all Razor views in the application.</remarks>
public virtual void BeforeCompile(BeforeCompileContext context)
{
var compilerOptionsProvider = _appServices.GetRequiredService<ICompilerOptionsProvider>();
var loadContextAccessor = _appServices.GetRequiredService<IAssemblyLoadContextAccessor>();
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
};
Expand All @@ -65,15 +60,5 @@ public virtual void BeforeCompile(BeforeCompileContext context)
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);
}
}
}

1 comment on commit 485e6e5

@davidfowl
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/cc @pranavkm unblocking the build. You might want to take a look

Please sign in to comment.