I am trying to get RazorGenerator.MsBuild to compile our CSHTML files on build. The issue I am having is that CSHTML pages that inherit from a custom WebViewPage throw a compile error. These CSHTML files work at run time if they are copied to the website, it is only the build that fails.
For example we might have the following CSHTML file:
public class MyWebViewPage : System.Web.Mvc.WebViewPage
{
public bool DoSomething()
{
return true;
}
}
And the following CSHTML:
@inherits MyWebViewPage
@if(DoSomething()){
}
This will cause the following error:
The name 'DoSomething' does not exist in the current context.
How can I get the MSBuild task to recognise my custom class?
This turns out to be a problem with the way that RazorGenerator.MsBuild generates code. When compiling it writes the inherited class as:
The generator requires a generic base view. The simplest solution is to alter MyWebViewPage to support generics: