I want an msbuild task to compile the views so I can see if there are compile time errors at well... compile time. Any ideas?
Join them; it only takes a minute:
|
I frankly would recommend the RazorGenerator nuget package. That way your views have a .designer.cs file generated when you save them and on top of getting compile time errors for you views, they are also precompiled into the assembly (= faster warmup) and Resharper provides some additional help as well. To use this include the RazorGenerator nuget package in you ASP.NET MVC project and install the "Razor Generator" extension under item under Tools -> Extensions and Updates We use this and the overhead per compile with this approach is much less. On top of this I would probably recommend .NET Demon by RedGate which further reduces compile time impact substantially. Hope this helps. |
|||||||||||||
|
From the readme word doc for RC1 (not indexed by google) ASP.NET Compiler Post-Build Step Currently, errors within a view file are not detected until run time. To let you detect these errors at compile time, ASP.NET MVC projects now include an MvcBuildViews property, which is disabled by default. To enable this property, open the project file and set the MvcBuildViews property to true, as shown in the following example:
Note Enabling this feature adds some overhead to the build time. You can update projects that were created with previous releases of MVC to include build-time validation of views by performing the following steps:
|
|||||||||||||||||||||
|
You can use aspnet_compiler for this:
where "/Virtual/Application/Path/Or/Path/In/IIS/Metabase" is something like this: "/MyApp" or "/lm/w3svc2/1/root/" Also there is a AspNetCompiler Task on MSDN, showing how to integrate aspnet_compiler with MSBuild:
|
|||||||||
|
Also, if you use Resharper, you can active Solution Wide Analysis and it will detect any compiler errors you might have in aspx files. That is what we do... |
|||||||||||||||||||||
|
Next release of ASP.NET MVC (available in January or so) should have MSBuild task that compiles views, so you might want to wait. See announcement |
|||
|
I don't know what viewengine you're using, but if you're using Razor, you might want to check out my blog post: Compile your asp.net mvc Razor views into a seperate dll Should be possible to use that code for other viewengines as well, but haven't done & tested that yet |
|||
|
The answer given here works for some MVC versions but not for others. The simple solution worked for MVC1 but on upgrading to MVC2 the views were no longer being compliled. This was due to a bug in the website project files. See this Haacked article. See this: http://haacked.com/archive/2011/05/09/compiling-mvc-views-in-a-build-environment.aspx |
|||
|
I simply use Productivity Power Tools (free) extension for Visual Studio. It does view/razor compile checks when building. Any errors will make the given views to be underlined in red, doing the same to all the file's higher ancestors in the solution explorer tree (i.e., the project the view is included, the solution...) |
||||
|
Build > Run Code Analysis Hotkey : Alt+F11 Helped me catch Razor errors. |
|||
|
protected by Community♦ Aug 24 '15 at 11:03
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?