Problem -
Recently, we moved our application from
Azure Website to Cloud Service. In website, we were using
pre-compilation as that gives a significant performance improvement.
When we moved to cloud service and wanted to use pre-compilation, we
found that this is not as easy as it was for website. For websites,
we are having option in Visual Studio (a check box that you can
check) to enable pre-compilation, but, Visual Studio does not provide
any such option.
Solution -
One very easy and effective solution
for this is to use RazorGenerator – a visual studio extension and a
Nuget package (you need both).
Steps to implement -
Below are the steps to implement
RazorGenerator for your ASP.NET MVC application -
- Install RazorGenerator from Visual Studio extension gallery.
- Install package RazorGenerator.mvc from Nuget package to your class library.
- Go to view > properties (you can get this by right clicking on the view file in solution explorer or pressing Alt + Enter).
- Set Custom Tool to RazorGenerator (you need to do the same for all existing views those you want to be precompiled).
- Save the property and you are done.
How
this works -
When
you set Custom tool to RazorGenerator, this will create a precompiled
.cs file named [yourViewName].generated.cs, and the .cs file will be
used when the application is running.


No comments:
Post a Comment