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?
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
.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With