Monday, October 04, 2010

Detecting Errors in Views at Compile Time

I got this tip from Steve Sanderson's fantastic book Pro ASP.NET MVC 2 Framework.

Open your ASP.NET Webforms or MVC .csproj file in WordPad and find:
<Target Name="AfterBuild">
</Target>
Make it look like this to cause views to compile when building in release mode:
<Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)" />
</Target>
Be aware of xml comments <!-- --> around the AfterBuild tags that will keep your change from getting used.

The effect is compiler errors in your views will show up when you compile in release mode, and not just when that view is open in Visual Studio.

No comments: