in

Platinum Bay

Peace, Love, Team System, and Community

This Blog

Syndication


.NETicated

Static Page Checking in ASP.NET MVC

If you have built an ASP.NET web forms site of any substance, you have undoubtedly been bitten when code in the web form becomes outdated due to code change. It’s easy to see when the page is open in Visual Studio, as the code has red squiggles and the error shows up in the Error List tool window. As soon as the page is closed however, that error disappears. Even running a build will be successful. For some of my sites, which have over 150 pages, this can be very annoying to say the least.

ASP.NET MVC has a neat hidden feature to solve this problem. The MVC team was most likely were stung by the same issue more than once. This feature is static page checking during compilation. Unfortunately, instead of being an option in the Properties window for the project (future release idea?), it is in the *.*proj xml file itself. To enable this feature:

  1. Right-click on the Project node in the Solution Explorer tool window
  2. Choose “Unload Project” - Note: If your project is under version control, you will be prompted to do a check-in. Simply click “Continue” to ignore the check-in request.
  3. Right-click the Project node again
  4. Choose “Edit *.*proj", and the project file will now open in Visual Studio with color coding and IntelliSense
  5. In the first PropertyGroup node, there is a new node named MvcBuildViews
  6. By default this is set to false. Simply change the value to true
  7. Right-click the Project node and choose “Reload Project”
  8. If prompted that the file is already open, click yes to close the xml view.
  9. Build your project

You will notice that builds take longer than they did prior to this change. This is because under the covers, MSBuild is now making an additional call to aspnet_compiler in the AfterBuild MSBuild target:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe -v temp -p "[physical path]"

To avoid this delay in day-to-day development, you may choose to copy the MvcBuildViews node into the build-specific PropertyGroup nodes, and set it to false for Debug and true for Release.

Update: @jglozano points out that this only works with the default WebForms View Engine.

Hope this helps

Published Aug 21 2009, 02:35 PM by Steve
Filed under: ,

Comments

August 21, 2009 11:42 AM

Yes, this is a very important thing to do and for some reason it isn't widely known. Thanks for sharing it with the community :)

 

August 21, 2009 7:21 PM

Hi Steve,

Yeah this is a great tip that never really made it out of the release notes to common knowledge.  Thanks for publishing this.  There is one tip I would like to give though and I talked to Phil about this back in January, but it never made it in to the final release.  The actual path you want to use for the compile is not:

$(ProjectDir)\..\$(ProjectName)

it should just simply be

$(ProjectDir)

And I will tell you why.  The first one doesn't work if your assembly isn't named the same as your project.  The second one works every time and it probably isn't publicized all that much because of this bug, which is very easy to fix.  I know why this happened internally with in the MVC team, and it should have been fixed before the release, but these things happen sometimes.

 

August 22, 2009 5:17 PM

Pingback from  Twitter Trackbacks for                 Static Page Checking in ASP.NET MVC - .NETicated         [platinumbay.com]        on Topsy.com

 

August 22, 2009 10:15 PM

Pingback from  Twitter Trackbacks for                 Static Page Checking in ASP.NET MVC - .NETicated         [platinumbay.com]        on Topsy.com

 

August 23, 2009 12:54 PM

Pingback from  Arjan’s World    » LINKBLOG for Aug 23 - 2009

 

August 23, 2009 1:44 PM

Pingback from  Dew Drop – August 23, 2009 | Alvin Ashcraft's Morning Dew

 

August 23, 2009 5:43 PM

Thank you for submitting this cool story - Trackback from DotNetShoutout

 

August 24, 2009 5:40 PM

DotNetBurner - burning hot .net content

 

September 15, 2009 9:36 PM

Pingback from  ASP.NET MVC Archived Blog Posts, Page 1

 

February 19, 2010 4:58 PM

Soma online cod payment. Soma online sales. Buy soma online. Soma buy soma cheap soma soma online. Best online pricing for soma. Soma online.

 

Leave a Comment

(required )  
(optional )
(required )  
Add

About Steve

Steve Andrews is a Team System MVP and INETA Speaker, and has been working as a developer for more than 9 years. During this time, he has designed and developed applications in such widely varying areas as trust accounting, medical information management, supply chain management, and retail systems. Steve is also an MCP, ICSOO, Speaker Liaison for the Philly .NET User Group, and community fanatic.
Powered by Community Server (Commercial Edition), by Telligent Systems
© Platinum Bay | Some Rights Reserved Creative Commons License

Disclaimer: The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Feel free to challenge me, disagree with me, or tell me I'm completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or annonymous comments) - so keep it polite, please.