Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

One scenario that many large development teams often ask me about is whether it is possible to split up/partition an ASP.NET web application into multiple projects within Visual Studio.  The goal with doing this is typically to improve the modularity of large sites and/or to improve the IDE compile-time performance for large projects.

VS 2003 supported splitting up a large site into multiple projects, although it is non-trivial to setup and manage.  With the VS 2005 Web Application Project option that we released earlier this spring, it is now pretty easy to set this up and manage it using VS 2005.

Omar Khan (the Group Program Manager for the VS 2005 Web Tools) has published two really great walkthrough posts that describe step-by-step how to setup Sub Web Projects using VS 2005:

-- Creating Sub-Projects in IIS using VS 2005 Web Application Projects: This post describes the basics of how to setup a multi-project solution that builds a single ASP.NET 2.0 application.

-- Creating Shared User Controls and Master Pages with Sub Projects: This post describes how to define master-pages and user controls within a root web project, and the use them within sub-projects in the application.

The above two posts show how to use sub-projects with IIS.  Omar's next post in the series will also then cover how to use the same technique with the built-in VS 2005 web-server.

One question I still get asked a lot is what is "the recommended" web project approach to take with VS 2005 -- use the VS 2005 Web Site Project option or the VS 2005 Web Application Project option?  The answer is "it depends on your style of working" - there is really no one single recommended way.  Some people love the web-site project model option; others think we were nuts and the web application project model option is the only way to go.  The reality is that both options are fully supported (meaning you can call up product support and ask for help or hotfixes), both will ship built-in to Visual Studio releases going forward (the web application project option will be included in SP1), and both are perfectly fine options to use depending on your personal preference and application structure.  Two articles you might find useful to debate this topic more is this MSDN whitepaper that includes some comparisons between the two models, and Rick Strahl's Web Application Projects and Web Deployment Projects are Here article that also was published in the Code Magazine and which provides a good discussion of the pros/cons of the different options.

Hope this helps,

Scott

P.S. Please visit this page to read more articles in my "ASP.NET 2.0 Tips, Tricks, and Gotchas" series.

Published Wednesday, August 16, 2006 12:54 AM by ScottGu

Comments

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Wednesday, August 16, 2006 4:34 AM by Anders G
I can recommend the Omar-way if you have large web projects and epically if you have a mix of ASP and ASP.NET. We've been using this approach since we switched from WSP to WAP this spring.

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Wednesday, August 16, 2006 5:54 AM by Mike
Not really related to subprojects and all, but why does one need to call support to get a hotfix?

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Wednesday, August 16, 2006 12:14 PM by Jeff Barton
Thanks Scott, this is MUCH appreciated.

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Thursday, August 17, 2006 1:49 AM by JasonBSteele
The clever thing about this method would appear to be directing the output of the sub-project to ..\bin. Does this means that you do not get a copy of all your BLL and DAL assemblies in your sub project bin? A present we do, which means we have two (or more) copies of the BLL and DAL assemblies loaded into memory!

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Tuesday, August 22, 2006 11:08 AM by Jeff
How about the option to create a Web Project in an existing folder -- just like VS 2003 can? Then there would be no need to jump through hoops to make VS 2005 work like it did in 2003.

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Tuesday, August 22, 2006 7:37 PM by ScottGu

Hi Jason,

Yep - using the approach above will allow you to avoid having two copies of the class libraries.  Instead you'll just have one copy in your \bin directory.

Hope this helps,

Scott

# re: WAP vs. WSP using VWD

Tuesday, August 29, 2006 12:36 AM by Dwayne J. Baldwin
You mentioned that Visual Studio SP1 will support both WAP and WSP models. Q) Will VWD (Visual Web Developer Express, RC or SP1) support WAP as well?

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Tuesday, August 29, 2006 1:03 AM by ScottGu

Hi Dwayne,

VS 2005 will support both WAP and WSP models in SP1.  Visual Web Developer Express edition will only support the web-site model (it doesn't have all the features needed to implement WAP).

We are, though, looking to support WAP with the express too with the next edition of Visual Web Developer Express Edition (codename Orcas).

Hope this helps,

Scott

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Tuesday, August 29, 2006 5:03 PM by Ryan Reid
I don't understand why all of the assemblies have to be in the root project's /bin folder. I want to create a sub-project, leave it's assembly in a separate /bin folder (referenced in the section). I've tried loading the assembly first and I still can't load a user control from a sub project unless it's assembly is in the root /bin folder.

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Wednesday, August 30, 2006 1:39 AM by ScottGu

Hi Ryan,

ASP.NET looks for assemblies in the \bin directory immediately underneath the application root.  That is why you need to setup the project to build the assembly there.

Note that if you want the sub-project to be a separate application, then you can keep the assembly in the \bin directory underneath it.  But if you want to have the projects make up one single application you need to copy it to the root \bin directory.

Hope this helps,

Scott

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Friday, September 1, 2006 2:01 AM by Ashish Agrawal
Why WAP use CodeBehind and WSP use CodeFile to specify vb code file? I think both can use same attribute.

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Friday, September 1, 2006 12:53 PM by ScottGu

Hi Ashish,

WAP uses a codebehind attribute since the control field declarations are declared in a .designer.cs/.vb partial class file that is maintained by Visual Studio.

Web Site Projects uses a codefile attribute to indicate that ASP.NET should dynamically create and maintain this partial class for you at compile-time.

Hope this helps,

Scott

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Tuesday, September 5, 2006 2:24 PM by terryb
Scott, Thanks for all the great info! I'm having good success with the sub projects and think it is the way we need to go. I'm running into problems with the accessability of session variables in the sub project created by the root project. You have any ideas on what may be my hold up? Thanks, Terryb

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Thursday, September 7, 2006 3:49 AM by ScottGu

Hi Terry,

You should be able to access session variables just fine in a sub-project.  One thing to check is that the sub-project is marked as a virtual directory and not as an application.  If it is showing up as an application in IIS it will have its own copy of session values -- which might be what you are running into.

Hope this helps,

Scott

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Monday, September 11, 2006 3:30 PM by Jason S
Scott, I discussed this same type of concept with you about 2 or 3 months ago. I'm so glad to see i was not the only one looking for this. A couple of questions. Deployment is always an issue. Is there a way to deploy only the changed sub project to production rather then the entire applicaiton? With many many modules, programmers, and clients on a single application deployment becomes a huge issue when we need to make a bug fix or version release. It would be nice to deploy only the dlls for that module or (sub project). We have many many modules with seperate programmers for each one. There might be 2 to 4 programmers that work on 1 module. What i would like to do is use the Primary Project for the Master Pages, Themes and such. Then each module is a sub project. I am assuming i can do that with this application. Is that correct? Lastly... Our applicaiton is a single code base and single database for many clients. Each client has a different "skin" (Theme). We query the database and get the theme that they want to use and set it at runtime. I would assume that there would not be any problems with this either. Is that correct? Thanks Jason

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Monday, September 11, 2006 3:38 PM by Jason S
Scott, One other thing that i was unclear on was how to deploy this. Did i simply miss it? Thanks J

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Monday, September 11, 2006 4:35 PM by ScottGu

Hi Jason,

I believe you should be able to use the Publish Web option in the build menu to publish the multiple sites to a location.

Hope this helps,

Scott

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Monday, September 11, 2006 4:44 PM by Jason S
I don't see a Publish Web option in the Build Menu. The only options i see are "Build Solution", "Rebuild Solution", "Clean Solution", "Build Application Name","Rebuild Application Name","Clean Application Name","Add Web Deployment Project" and "Configuration Manager" Am i missing somthing? I am using Wab Applications and not Web Sites. Thanks j

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Monday, September 11, 2006 4:55 PM by ScottGu

Hi Jason,

Are you not see a Build->Publish menu option?  You should be able to use the dialog here: http://weblogs.asp.net/scottgu/archive/2006/03/27/New-Publish-Feature-with-VS-2005-Web-Application-Projects.aspx

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Thursday, September 14, 2006 4:41 PM by Nicolas
Hi Scott, I would like to know if it is possible to prevent the switch of AutoEventWireup from false to true (and the deleting of the correponding event bindings in the code behind) where upgrading Web project from VS 2003 to a VS 2005 Web Application Poject ? Thanks!

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Friday, September 15, 2006 2:53 AM by ScottGu

Hi Nicolas,

If you use the "Convert to Web Application" option it will set AutoEventWireup to true.  If you skip this step then it won't.

Note that after you do the conversion, you can also always switch it back to false if you want and manually wire-up the page events yourself.

Hope this helps,

Scott

# re: Tip/Trick: Creating Sub-Web Projects using the VS 2005 Web Application Project Option

Tuesday, January 9, 2007 7:09 PM by Stefan

I realize that I'm coming to this post late, but would like to know if there are any plans to provide fully supported sub-Web projects, possibly in Orcas?