Posted by Anuraj on Wednesday, December 28, 2016 Reading time :1 minute
This post is about compiling your ASP.NET Core MVC Views. Normally in ASP.NET MVC, the views are not compiled until they are requested by the browser. To avoid this you can precompile the views. Precompile also helps to identify any errors upfront than at runtime.
In previous versions in ASP.NET MVC, you can do this by adding / setting
<MvcBuildViews>true</MvcBuildViews> in your CSProj file.
In ASP.NET Core 1.1, Microsoft introduced Precompile tools. You can do this by adding
ViewCompilation.Tools in the tools section and you can either run it manually or can be as part of
Here is the project.json file. (Included required references only)
And here is the postpublish script section.
Now you can run
dotnet publish command, which will compile the code and views, once it is successfull, you can remove the Views folder or you can use the exclude the option. In previous versions of ASP.NET, the views should not be removed, it was place holders, but in ASP.NET Core, Views are compiled to a DLL.
You can test the application, using
dotnet <dllname>, which will host the application in Kestrel HttpServer.
Happy Programming :)
What do you think? I would like to hear your thoughts, suggestions, and questions in the comments section below.