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?

user44070 Published in September 20, 2018, 4:47 pm

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?

share|improve this question

active oldest votes

Your Answer

StackExchange.ifUsing("editor", function () { StackExchange.using("externalEditor", function () { StackExchange.using("snippets", function () { StackExchange.snippets.init(); }); }); }, "code-snippets"); StackExchange.ready(function() { var channelOptions = { tags: "".split(" "), id: "1" }; initTagRenderer("".split(" "), "".split(" "), channelOptions); StackExchange.using("externalEditor", function() { // Have to fire editor after snippets, if snippets enabled if (StackExchange.settings.snippets.snippetsEnabled) { StackExchange.using("snippets", function() { createEditor(); }); } else { createEditor(); } }); function createEditor() { StackExchange.prepareEditor({ heartbeatType: 'answer', convertImagesToLinks: true, noModals: false, showLowRepImageUploadWarning: true, reputationToPostImages: 10, bindNavPrevention: true, postfix: "", onDemand: true, discardSelector: ".discard-answer" ,immediatelyShowMarkdownHelp:true }); } });
StackExchange.ready( function () { StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48715367%2fhow-can-i-get-precompiled-razor-files-when-deploying-net-web-application%23new-answer', 'question_page'); } );

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged asp.net-mvc iis razor precompile or ask your own question.

StackExchange.ready(function () { StackExchange.responsiveness.addSwitcher(); }) (function(i, s, o, g, r, a, m) { i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function() { (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o), m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m); })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga'); StackExchange.ready(function () { StackExchange.ga.init({ sendTitles: true, tracker: window.ga, trackingCodes: [ 'UA-108242619-1' ] }); StackExchange.ga.setDimension('dimension2', '|asp.net-mvc|iis|razor|precompile|'); StackExchange.ga.setDimension('dimension3', 'Questions/Show'); StackExchange.ga.trackPageView(); }); /**/ var _qevents = _qevents || [], _comscore = _comscore || []; (function() { var ssl = 'https:' == document.location.protocol, s = document.getElementsByTagName('script')[0], qc = document.createElement('script'); qc.async = true; qc.src = (ssl ? 'https://secure' : 'http://edge') + '.quantserve.com/quant.js'; s.parentNode.insertBefore(qc, s); _qevents.push({ qacct: "p-c1rF4kxgLUzNc" }); /**/ var sc = document.createElement('script'); sc.async = true; sc.src = (ssl ? 'https://sb' : 'http://b') + '.scorecardresearch.com/beacon.js'; s.parentNode.insertBefore(sc, s); _comscore.push({ c1: "2", c2: "17440561" }); })();
You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO