Terry Thibodeau's Blog

Welcome to Terry Thibodeau's Blog Sign in | Join | Help

Visual Studio *Magic* - Update (RTFM!)

Well, it turns out that Scott Guthrie has a nice little tutorial on Upgrading VS 2005 Web Site Projects to be VS 2005 Web Application Projects. All of the issues I was facing from my previous post are actually covered in this tutorial, which is why you must always RTFM! :)

From the tutorial:

One difference between a VS 2005 Web Site Project and a VS 2005 Web Application Project is that the VS 2005 Web Site Project Model dynamically generates the tool-generated partial class half of a page, and does not persist it on disk. The VS 2005 Web Application Project model on the other-hand does save this partial class on disk within files that have a .designer.cs extension and compiles it using the in-memory VS compilers when a build occurs (one benefit of this is faster build times). You can learn more about how this code-generation model works by reading this tutorial.

And, they do have a tool for fixing up the designer.cs file dependencies:

To convert pages and classes within the project, right click the root node of the Web Application Project and select "Convert to Web Application". This will cause VS 2005 to recursively examine every page, user-control, and master-page in the project and automatically generate a .designer.cs file for each, as well as change the .aspx/.ascx files to use the "codebehind" rather than the "codefile" attribute. This command will also rename App_Code to Old_App_Code. When it's completed your project will look as follows:

I'm still not sure why "codebehind" is used instead, but I assume it's to make the distinction between the simulated VS2003 way of doing codebehinds and the VS2005 (ASP.NET 2.0) way of doing things.

Finally, the namespace issue is also covered:

Note that .aspx, .ascx, .master, .ashx, .asmx, and .asax files contain "inherits=" or "class=" attributes that list the class names they should invoke. So if you add namespaces to the code-behind files of these types you will also want/need to update the inherits and class declarations to also contain the namespace you use. For example: a Details.aspx page would need to have its page directive changed from "inherits=Details_aspx" to "inherits=WebApplication5.Details_aspx"

In my defense, I didn't actually know that I was converting from Web site to Web Application Project, I just saw that files were missing. Oh well, this is why I love running into and solving issues like this: I'll always know what the problem is when I run into it again!

Regardless of the support in VS for fixing these issues, I still hold to the belief that generated code sucks. Because of VS generating the CodeFile partial class information for my page controls, I spent too much time trying to piece things together and search for reasons. If there weren't hidden, *magic* code thingies happening "for me", I probably would have seen the answer right in front of my face.

Just my opinion... ;)

Published Wednesday, March 07, 2007 10:44 AM by Terry Thibodeau
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server (Personal Edition), by Telligent Systems