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

OptimizationLevel specified in the dependency context \ primary assembly's project.json is never used when compiling views #4902

Closed
pranavkm opened this issue Jun 23, 2016 · 3 comments
Assignees

Comments

@pranavkm
Copy link
Contributor

DependencyContextViewEngineOptionsSetup and RazorViewEngineOptionsSetup modify compilation options - the first based on what's specified in the dependency context and second based on IHostingEnviornment.EnvironmentName. However the former setup's option values are always overwritten by RazorViewEngineOptionsSetup which runs second.

Additionally, the value set in OptimizationLevel determined in DependencyContextViewEngineOptionsSetup is incorrect - https://github.com/aspnet/Mvc/blob/dev/src/Microsoft.AspNetCore.Mvc.Razor/Internal/DependencyContextRazorViewEngineOptionsSetup.cs#L60-L62 needs to be inverted so that when your project.json says optimize, we choose Release.

@rynowak
Copy link
Member

rynowak commented Jun 24, 2016

What's the impact of this? Does this mean we're compiling optimized views for Debug and un-optimized for Release?

If I'm a user and I want to correct this setting, what's my best bet?

@pranavkm
Copy link
Contributor Author

@rynowak - the current behavior is Development -> Debug, Staging \ Production etc -> Release, so it's not entirely too bad. However, if you had "optimize": true in your project.json while in Development, views would continue to compile in Debug. You can use the RazorViewEngineOptions.CompilationOptions to change this:

services
.AddMvc()
.AddRazorOptions(options => 
{
  options.CompilationOptions = options.CompilationOptions.WithOptimizationLevel(
#if DEBUG
   OptimizationLevel.Debug
#else
   OptimizationLevel.Release
#endif
);
});

@pranavkm
Copy link
Contributor Author

pranavkm commented Jul 8, 2016

Self assigning. The code change is pretty minimal, most of the change here would be to add tests.

pranavkm added a commit that referenced this issue Jul 8, 2016
pranavkm added a commit that referenced this issue Jul 15, 2016
pranavkm added a commit that referenced this issue Jul 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants