Precompile not working in razor pages

372 Views Asked by At

I am new to Razor Pages (and have never done MVC), and it would really help me learn if I could precompile, but I can't get it to work. I have a newly created project in Visual Studio with Razor 3.2.4 and WebPages 3.2.4.

My project has a single index.cshtml and an _Layout.cshtml file, along with css files. I have also added Entity Framework 6.2.0 to the project, but I don't think that's relevant because the problem occurs when not using any EF code.

The documentation I can find says it precompiles by default, starting several releases ago. In spite of this I have added MvcRazorCompileOnPublish to the project, like this:

...
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<UseIISExpress>true</UseIISExpress>
...

The index.cshtml file contains the following:

@{ Layout = "/Pages/_layout.cshtml";}
@Model Index.cshtml.cs
@{
    int  i == 21;
}

The compilation error (or any one I introduce) is not caught caught until runtime. I've read a number of articles, but cannot find anything that seems to apply.

0

There are 0 best solutions below