2

This is an extension of the question "How to compile cshtml before runtime" Which I have implemented.

The problem I'm facing is that when I force MVC to prebuild the CSHTML, it starts trying to build all the Temp files as well.

It is finding files in paths like this:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\temp\272abf22\b789edae\App_Web_zej33svj.2.cs

Since the files are translations of the CSHTML files (to their actual CS form), and incomplete by themselves, it raises exceptions. This feels like a broken product. (which is probably why Microsoft keeps that option XML only, and not configurable through the UI.)

Community
  • 1
  • 1
  • What is the compiler error? Are you attempting to precompile an incomplete web-application? – Dai Jun 12 '14 at 20:21
  • in this case the compile errors don't matter. they are unknown reference errors on the temp files, because it has references to classes in the project, but the temp files are not actually part of the project. –  Jun 12 '14 at 20:45
  • That, and the compiles under normal settings, but when I get to a particular page, it throws compile errors, because there was invalid C# code in the cshtml file. the issue is to detect these issues at build time, instead of at run time. –  Jun 12 '14 at 20:47

1 Answers1

1

For compiling views instead of set MvcBuildViews to true, you can use Razor Generator for compiling views. This is a Custom Tool for Visual Studio that allows processing Razor files at design time instead of runtime, allowing them to be built into an assembly for simpler reuse and distribution. When you want publish your mvc application you have to set MvcBuildViews to false.

Mohsen Esmailpour
  • 11,224
  • 3
  • 45
  • 66
  • I've installed it now, but I don't see how to use it. I couldn't find that on the site either. Is it just supposed to work when building? –  Jun 12 '14 at 20:48
  • [compile only one view](https://razorgenerator.codeplex.com/wikipage?title=Quick%20Start%20Guide&referringTitle=Documentation) or for compiling all view run `Enable-RazorGenerator` in Nuget Package Manager Console or you can use [RazorGenerator Engine](https://razorgenerator.codeplex.com/wikipage?title=Precompiled%20MVC%20Views&referringTitle=Documentation) – Mohsen Esmailpour Jun 12 '14 at 20:54