Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make builds fail in VS 2013 if there's a razor/C# error in a .cshtml file? [duplicate]

I'm new to asp.net mvc. I see nasty little red underlines on my .cshtml page in some razor code with errors in the error list, but the project still builds. Can I fail the project build somehow if these errors are about?

As an aside, if I rename a variable in a c# class referred to in a razor page, why doesn't the refactor tool extend its reach to the cshtml file?

like image 508
Isaac Bolinger Avatar asked Nov 22 '13 23:11

Isaac Bolinger


2 Answers

You need to set in your project to compile views during build.

Set in your MVC project:

<MvcBuildViews>true</MvcBuildViews>

All you have to do is unload or close the mvc project in Visual Studio, edit the .cspoj file (in VS or notepad or your favourite editor), locate <MvcBuildViews> and change the value to true.

like image 111
Romias Avatar answered Nov 15 '22 14:11

Romias


It could be smart using the MvcBuildViews setting only for Release builds, assuming your build process uses a Release build before you deploy. This will remove the extra wait to compile the views when you’re developing and debugging, but still keeps a check in place before you deploy. Add the MvcBuildViews node to the PropertyGroup node for Release builds only. It will look something like this:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
    <MvcBuildViews>true</MvcBuildViews>
</PropertyGroup> 

http://blog.falafel.com/get-compile-time-view-errors-in-asp-net-mvc/

like image 4
Dennis Rosenbaum Avatar answered Nov 15 '22 15:11

Dennis Rosenbaum