0

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.

Jim S
  • 1,069
  • 3
  • 10
  • 17
  • [Microsoft](https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?tabs=aspnetcore2x) says that precompilation is a feature of ASP.NET Core. Are you sure this is a Core project? The inclusion of EF 6 (instead of EF Core) suggests otherwise. – Bradley Uffner Mar 02 '18 at 02:42
  • If this is a Core project, are you actually *Publishing* it? Precompilation takes place only when you publish, not when you build / debug the application. – Bradley Uffner Mar 02 '18 at 02:47
  • You were right on both counts. Thank you! – Jim S Mar 03 '18 at 16:02

0 Answers0