Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pre-compile razor views in asp .net mvc 5

I have an ASP .Net MVC5 website, I have performance issues, I want to pre-compile the razor views and exclude them when deploying my website in IIS, I followed the steps indicated in this article but I got an error : RazorGenerator.targets was not found, in fact I checked in the package folder I din't find this file. Do you have any idea why this dll not found in the package folder ? The RazorGenerator.Mvc and RazorGenerator.MsBuild are installed correctly. Thanks in advance

like image 339
Bilel Chaouadi Avatar asked Nov 12 '15 15:11

Bilel Chaouadi


People also ask

What is Razor view engine MVC 5?

Razor View Engine is a markup syntax which helps us to write HTML and server-side code in web pages using C# or VB.Net. It is server-side markup language however it is not at all a programming language.

Do Cshtml files get compiled?

cshtml extension are compiled at both build and publish time using the Razor SDK. Runtime compilation may be optionally enabled by configuring your project.

Can I add Razor page to MVC project?

You can add support for Pages to any ASP.NET Core MVC app by simply adding a Pages folder and adding Razor Pages files to this folder.

How do I enable Razor runtime compilation?

You just need to check “Enable Razor runtime compilation” when you're creating a new project. Moreover, this option is available when choosing the target framework starting from version 3.1 to the current version 5. x. Remember these when you are creating a new ASP.NET Core or ASP.NET Core MVC projects.


1 Answers

You don't need RazorGenerator for this. When publishing just set the option to "Precompile during publishing", under "File Publish Options" on the "Settings" tab. Click "Configure" and then tick "Merge all outputs to a single assembly". Give it a unique name, generally something like [ProjectName].Precompiled.

like image 85
Chris Pratt Avatar answered Oct 26 '22 23:10

Chris Pratt