Home How can I get precompiled razor files when deploying .NET Web Application?
Reply: 0

How can I get precompiled razor files when deploying .NET Web Application?

John Dover
John Dover Published in 2018-02-09 23:01:33Z

I am tasked with improving IIS preloading and initializing of applications on our server. I have implemented application initialization and preload of application on IIS, but still there is a long wait time when recycling/restarting application pool. I have found some useful links which I thought would help me, but I am still not getting precompiled Razor views. I tried to follow this article for RazorGenerator, but it does not seem to work. http://blog.davidebbo.com/2011/06/precompile-your-mvc-views-using.html

Steps I have taken for above article

1) installed VS Extension from here: https://marketplace.visualstudio.com/items?itemName=DavidEbbo.RazorGenerator

2) installed nuget package RazorGenerator.Mvc

3) changed output to 'None' on razor views and set 'Custom Tool' to 'RazorGenerator' as described in article above.


I do a clean and rebuild, but do not see a .cs file for my cshtml file.

Ok, so then I think this doesn't work, lets try something else...Lets just try the precompiled feature that visual studio comes with out of the box as this post's answer suggests:Pre-compile razor views in asp .net mvc 5, but still no precompiled cshtml files.

What I would like to accomplish is this how can I generate these files before hand so that IIS does not have to. This is an image of IIS temporary cache files after a recycle/restart

This is an image after browser has requested the application

And lastly on that publish I had used visual studio precompile (for the two images above) so i am attaching my publish options image as well.

Ok... now i think there is no way that this is possible, but then find another SO solution here: VS2013 does not compile ASP.NET MVC5 views , but again with that publish I still do not see the compiled versions of the cshtml files in the temporary IIS cache for my application. Is there a solid solution out there that anyone can suggest that will actually precompile the cshtml files in my application so that they are not generated on first browser request? I even have application initialization in my web config and the required IIS feature installed, and can even see that it does fire a "fake" request to my application, however the cshtml files do not get compiled on that "fake" request. Sorry if I have attached to much information, but seems like each question I ask on here I am not providing my actual question...=( Hopefully this question serves it's purpose. Thanks!


Last article above suggests to change csproj file so I have tried that as well and attaching screen shots of that file.

And the Action at the bottom of the file

Changing "temp" to "/" does not help as well.


So, after being away from the computer for the weekend I noticed this morning that I had "Allow precompiled site to be updateable" checked. After unchecking that value I started seeing the precompiled views in my bin folder. So I publish my application thinking that at most I would wait 5-10 seconds for application to be served (Usually after it has been requested the first time it only takes about 2 seconds), but it still takes 25-30 seconds. Is this an expected behavior with IIS?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.296847 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO