Search code examples
asp.net-mvcvisual-studio

ASP.NET MVC: how to signal compilation error if a view has error?


My view has errors. I see these errors only if I open the view in Visual Studio.

I would like to see the errors on compile time rather than on execute time.

Does exist a way to obtain this behavior?


Solution

  • You can update by hand the .csproj file and add a <MvcBuildViews>true</MvcBuildViews> that will compile the views as you go.

    Here's a link I googled, you'll find others as well.

    EDIT: If it's too slow try setting the build only for Release, edit the csproj file doing something like this; see the docs for AspNetCompiler for more details.

    <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
       -->
    <Target Name="BeforeBuild">
    </Target>
    <Target Name="AfterBuild">
        <AspNetCompiler VirtualPath="Temp" PhysicalPath="$(ProjectDir)\..\$(ProjectName)" />
    </Target>