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

Razor Precompilation #3917

Closed
pranavkm opened this issue Jan 12, 2016 · 19 comments
Closed

Razor Precompilation #3917

pranavkm opened this issue Jan 12, 2016 · 19 comments

Comments

@pranavkm
Copy link
Contributor

pranavkm commented Jan 12, 2016

Summary

We want to bring back Razor Precompilation so that you can ship an assembly or app with views baked in. We're going to start developing this during the 1.1.0 timeframe based on a prototype from https://github.com/aspnet/Performance/tree/dev/testapp/RazorCodeGenerator

Goals:

  • Faster startup time (traded for build time)
  • Find errors at build time
  • Same Razor programming build as runtime compilation
  • Loading/detection of precompiled views on by default (doing compilation requires a gesture)

Non-Goals:

  • Support for replacing a precompiled view with a 'local' view

Details

Our plan is to implement precompilation via a command line tool. We have an existing tool that can generate .cs files given a project - we need to make that tool production quality and then add the ability to compile the generated code and embed it as a resource in the application assembly.

We'll also add support to the view engine to detect and use embedded view assemblies automatically via application parts. This means that dependencies you reference can include precompiled views.

The biggest unknown here is how exactly we'll interface with your application's startup code path when you've configured Razor to include extra application parts or references. We need to start productionizing what we have and look at gaps.

@ToddThomson
Copy link

@pranavkm I took a look at the EmbeddedFileProvider and it seems like a reasonable alternative. I really don't care about razor precompilation as long as I can package views ( cshtml embedded file ) into a nuget class library package. The new dotnet cli can handle this now using the "resources" property - correct?

@pranavkm
Copy link
Contributor Author

@ToddThomson , yes. There's a bunch of discussion around using this pattern here - #3750

@ToddThomson
Copy link

@pranavkm OK. Using CompositeFileProvider with multiple EmbeddedFileProvider instances provides me with what I need. I had built a dynamic module view provider over the base PrecompiledViewProvider, but this may work out better. Thanks for your help.

@Eilon Eilon modified the milestones: 1.0.0, 1.0.0-rc2 Mar 18, 2016
@Eilon Eilon modified the milestones: Backlog, 1.0.0 May 5, 2016
@Eilon
Copy link
Member

Eilon commented May 5, 2016

Moving to backlog.

@rstarkov
Copy link

rstarkov commented Jun 8, 2016

Is there no way to spot a syntax error or a typo at compile time anymore?

@pranavkm
Copy link
Contributor Author

pranavkm commented Jun 8, 2016

@rstarkov, you might be able to create a executable around MvcRazorHost to codegen cs files for you as part of build and then try compiling it with the rest of your code. But there isn't a tool targeting MvcCore that supports it as yet.

@zgover
Copy link

zgover commented Jul 10, 2016

Anyone have an estimate of when this will be prioritized for a specific release?

@Eilon
Copy link
Member

Eilon commented Jul 19, 2016

@Zachary1748 we have @rynowak working on a new implementation of Razor precompilation with @DamianEdwards .

@rynowak @pranavkm should we do anything with this bug? Is the new stuff related in any way to the old stuff?

@Eilon Eilon modified the milestones: 1.1.0, Backlog Jul 19, 2016
@rynowak
Copy link
Member

rynowak commented Jul 19, 2016

Updating the top-post

@rynowak rynowak changed the title Find a new home for Razor precompilation Razor Precompilation Jul 19, 2016
@rynowak
Copy link
Member

rynowak commented Jul 19, 2016

Main post updated

@tuespetre
Copy link
Contributor

I've put together something to get us by until an official solution arrives:

https://github.com/tuespetre/dotnet-precompile-views

I'm really sad they removed the ICompileModule interface now; it would have been awesome to just add the precompiled views to the main compilation.

@pranavkm
Copy link
Contributor Author

pranavkm commented Aug 3, 2016

@tuespetre I tried messing around with CCI to do this - https://github.com/aspnet/Mvc/pull/5087/files#diff-8a8d40881a0fbe5921c1000c1f6016edR72. Unfortunately it has issues (CCI can't strong name assemblies) and it's in support mode so we're considering not doing this. Mono.Cecil supports strong naming but the package hasn't hit 1.0 as yet and doesn't support netstandard TFMs.

@Eilon
Copy link
Member

Eilon commented Aug 19, 2016

Done?

@pranavkm
Copy link
Contributor Author

pranavkm commented Aug 19, 2016

Not really. Need to check in the other piece.

@pranavkm pranavkm reopened this Aug 19, 2016
@Eilon
Copy link
Member

Eilon commented Aug 19, 2016

Ok 😄

@pranavkm
Copy link
Contributor Author

First iteration done: aspnet/MvcPrecompilation@dbe93ac.

Second pass includes addressing naming \ design for view discovery components in Mvc, adding more sample \ test scenarios, and performance.

@MartinJohns
Copy link

So it's not done, but the Done label is added and the issue is closed? And the link @pranavkm posted leads to a 404.

@pranavkm
Copy link
Contributor Author

@MartinJohns we hadn't set up some of non-code aspects on the repo (licensing \ README, CLA bot etc) as yet. We'll get it made non-private once that's done, which should be very soon.

@pranavkm
Copy link
Contributor Author

@MartinJohns - repo is public now - https://github.com/aspnet/MvcPrecompilation.

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

9 participants