Friday, April 8, 2011

Turn on Compile-time View Checking for ASP.NET MVC Projects for DEBUG only

I wrote a post about "Turn on Compile-time View Checking for ASP.NET MVC Projects" Today, we got a annoying problem with it. Our team have a gate checkin in TFS. Basically, it will build the solution when someone checks in code and if it builds successfully as well as all tests pass, the checkin will be approved. Some dude in our team did some code mergings and then checked in with so many errors on View files so we got serveral complains from the testers when they tested those pages. I expected my changes in the project configuration would not effect these builds on TFS because the MvcBuildViews would only be ignored on DEBUG configuration. And I also made an assumtion that the GateCheckin build on TFS didn't use DEBUG configuration but it did indeed. Actually, the GateCheckin was setup long time ago by someone and it was not set to choose a build configuration. So if you look in the top of the project file, you will see that if there is no configuration setup, the DEBUG will be default:

<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
We raised this issue to the IT guy, just asked him to set the default build configuration for the GateCheckin because we don't have enough permission to change that. But there are not any responses... for some reasons :D. So I decided to cheat the build server myself. I change the line in the project configuration to something like:
<MvcBuildViews Condition=" '$(MvcBuildViews)' == '' Or '$(Configuration)' != 'Debug' ">true</MvcBuildViews>
The MSBUILD can get the property value from Environment Variables. That's how i cheat the build. The build server will never have MvcBuildViews in it's Environment Variables so it will have MvcBuildViews set to "true" always. In developer machines, we setup a system variable MvcBuildViews and set to false. This step will help skipping the view compilation while debugging, switch to Release or something else to compile the views when you want. Please note that it's neccessary to logoff then login or just restart the PC to make the environment variable take effect. Cheers

0 comments:

Post a Comment