Could not precompile the input file contents...

Jul 9, 2013 at 2:56 PM
I'm attempting to integrate RazorGenerator MSBuild into a large MVC 4 project (targets .NET 4.0) as instructed in the following link.

I'm getting the following error on build and wondering if there is any output file or somewhere I can dig to find out which view(s) are the problem?

Could not precompile the input file contents. Ensure that a generator declaration exists in the cshtml file.
A generator declaration is the first line of your cshtml file and looks like this:
@* Generator: MvcHelper *@
Valid host names: MvcHelper, MvcView, Template, WebPagesHelper, WebPage, RazorGenerator.Core.IHostProvider

Any help would be greatly appreciated.
Jul 11, 2013 at 5:02 AM
There's some heuristic involved in determining what kind of file to generate from the cshtml file. For Mvc apps, we look for things like the presence of System.Web.Mvc in the project references and that's not very accurate at times.

Could you try dropping a file named razorgenerator.directives at the root of your application with this token and see if that helps?
Generator: MvcHelper
Additionally, it would be great if you could share a stripped down version of your csproj - it might help in fixing the heuristics.
Jul 11, 2013 at 4:57 PM
The razorgenerator.directives file exposed at least one problem. We use Areas extensively, and rather than including a _ViewStart.cshtml file under each Area we place ViewStart in the root of the application. Then modify the root web.config file adding a sectiongroup and section for system.web.webPages.razor. So with the razorgenerator.directives file in place I now see an "Identifier expected" build error in _ViewStart.cshtml.cs due to the fact that the namespace includes a trailing period.
namespace Mvc4RazorGenTest.
I was able to remove the trailing period and build successfully in my test project. I have another error in my real project, but I am investigating that a little further. This was fairly easy to reproduce by creating a new MVC4 project with VS 2012, but let me know if you still need a csproj.