Can Razor views be compiled?

后端 未结 4 1622
别跟我提以往
别跟我提以往 2020-11-27 13:33

I was wondering if Razor views could be compiled, like WebForm based views?

Does it even make sense to compile Razor views and why would somebody want to do that?

4条回答
  •  执笔经年
    2020-11-27 14:00

    Edit:

    Here is a blog post on this topic as well:

    How to Detect Errors of Our ASP.NET MVC Views on Compile Time

    To make your views to be compiled, do the following;

    1. Unload your project by right clicking the project on the solution explorer in VS and clicking unload project
    2. right click the project which has been converted to unavailable project and click "Edit your_project_name.csproj" (that would be .vbproj if your project is VB project)
    3. see the following code;

      
      
      v4.0
      false
      

    4. change the MvcBuildViews tag value from false to true

    5. after that save it and reload your project.

    after you build your solution to compile it, you will see that your view will be compiled too.

    NOTE: to test it, break some code in one of your view on purpose and try to build. you will see that you'll get an error message.

提交回复
热议问题