Welcome to MSDN Blogs Sign in | Join | Help

Visual Web Developer Team Blog

Your official information source from the Visual Web Developer team.

News

  • These postings are provided "AS IS" with no warranties, and confer no rights. Use of included code samples are subject to the terms specified Terms of Use
Part 1 of 3: Creating sub-projects in IIS with Web Application Projects

First a quick intro, since this my first post on the team blog.  My name is Omar Khan.  I'm the group program manager for the web development tools team.  I manage the program management team that helps design the web tools inside of Visual Studio.

This post is one of a three part series that describes how to factor development of a single large ASP.NET application into multiple projects inside of Visual Studio 2005 using the Web Application Projects add-in.

Part 1 of 3: In this post, I’ll describe the basics on how to setup a sub-project structure using IIS. 

Part 2 of 3: The next post will describe intricacies with master pages, user controls, and project references when using a sub-project structure.

Part 3 of 3: The final part to the series will describe how to use the same technique but with the built-in development server in Visual Studio 2005.

Why use sub-projects?

With very large web applications, such as those that contain thousands of files, using a sub-project structure in Visual Studio provides several benefits. 

At development time, it provides a clean isolation between different parts of the application.  This enables different developers to own their own projects within a single web application, and allows them to make changes without affecting code that is in a different project.

As well, using sub-projects provides a clean way to compartmentalize functionality so different parts of the application can be developed in isolation from others.  The compartmentalization also enables the ability to deploy the various sub-projects to production independently from each other thus providing more flexibility around incremental updates to one part of the application without affecting other parts. 

Setting up the root project using IIS

The first thing I want to show is a step-by-step on how to setup a sub-project project structure based on developing on IIS. 

Setting up a sub-project structure in Visual Studio 2005 is fairly straightforward.  If one has done it in Visual Studio 2003, the process described below should be very familiar. 

Here is a step-by-step walkthrough of how to setup sub-projects using Visual Studio 2005 and the Web Application Projects add-in.

1)    Download and install “Web Application Projects” add-in.  The add-in can be installed from the following location: http://msdn.microsoft.com/asp.net/reference/infrastructure/wap/default.aspx

2)    Create the root project.  The first thing we want to do is create a new Web Application project that will represent the root of the application in IIS.  To do this select File > New Project.  Choose the ASP.NET Web Application item, and type in a name and location for the root project.  In this example we’ll call the root project MyLargeWebApp.  Make sure the “Create directory for solution” checkbox is unchecked.  One can create the “Root” project in a folder in the “inetpub/wwwroot” directory for IIS, or in any other location where you wish to create the virtual root for your app.  In this example, we’ll use a location underneath “inetpub/wwwroot”. 

 

 

3)    The next step is to map the MyLargeWebApp project in IIS using the “Web” tab in project properties.  To do this, right-click on the root node of the project and select “Properties”.  Click the “Web” tab on the page that is launched, and select the “Use IIS Web Server” option.

  

4)    Next you need to create a virtual directory mapping in IIS to point to the location where your root project exists.  To do this click the “Create Virtual Directory” button on the same Properties page.

 

5)    You can now test your root project, by adding some content to default.aspx and selecting F5.  This should run launch IE and the default.aspx page will get served from IIS.

 

Creating sub-projects under a root project

Once the root project is up and running fine, the next step is to create a sub-project and set it up so it builds and runs as part of the same ASP.NET application represented by the root project.  The following steps describe how to do this:

1)    The first thing you need to do is add a new Web Application project to the same solution.  Make sure the MyLargeWebApp solution/project is already open in the solution explorer.  To add a new project to the solution, select “File > Add > New Project”.  Select “ASP.NET Web Application” as the template.  Then type in a name for the sub-project (“SubProject1” in this example), and set it to the location of the folder where the root project is (c:\inetpub\wwwroot\MyLargeWebApp in this example).

 

 

 

2)    You should now have two projects in your solution which represent a single ASP.NET application.  To verify this, go to the IIS management console by selecting Start > Run > inetmgr in Windows.  In the management console, you should see a “SubProject1” folder under single IIS web application called “MyLargeWebApp”.

 

 

3)    To get the sub project building and running a few more steps are required in Visual Studio.  The first thing you should do is delete the web.config file in the sub-project.

 

4)    Next you need to adjust a few of the properties for the sub-project.  Right click on the sub-project’s node in solution explorer and select “Properties”.  Under the “Compile” page change the “Build output path” to “..\bin\”.

 

 

 

5)    Finally in the sub-project’s properties, under the “Web” page, select the “Use IIS Web Server” option and change the “Project URL” setting to “http://localhost/MyLargeWebApp/SubProject1”.  Also check the "Overwrite application root URL" and provide the URL to the root project, which in this case is "http://localhost/MyLargeWebApp/".  Do not click the “Create Virtual Directory” button in the sub-project’s setting as you don’t want to create another application root in IIS at the sub-projects folder.

 

6)    Once you’ve updated these properties for the sub-project, the sub-project should be ready to go.  Add some content to the default.aspx page in the sub-project and press F5.  This should build the sub-project, deploy its DLL to the \bin of the root project, and then run the page from the sub-project.  If you select the root-project and “Show All Files” in the solution explorer, you will see in its \bin folder that there are two deployed assemblies, one for the root project (MyLargeWebApp.dll) and one for the sub-project (SubProject1.dll).

 

 

Summary

This wraps up my first post on sub-projects.  Hopefully it provides a quick introduction on how to setup a sub-project structure using the Web Application Project add-in for Visual Studio 2005. 

As mentioned in the beginning of the post, sub-projects are a good way to partition a single large ASP.NET application into several Visual Studio projects so you get the benefits of isolated development and deployment.

Looking forward to hear from you about this post, and I'll update with Part 2 hopefully next week.

--Omar

Posted: Saturday, July 01, 2006 1:51 AM by WebDevTools
Filed under: , ,

Comments

Imran said:

This article is great as i was planning to have some plug and play modules in my web application. Can you tell me how i can achieve similar thing using the default web architecture in VS 2005.

Also when i compile how will i have to do the compilation if i only want one module to be compiled.

How can i call the web.config connection string etc. in the master project from the sub project files.

Also where are the other 2 parts of this article :).

Thanks,
Imran
# July 3, 2006 11:36 PM

markoh said:

The advice with setting project output to ..\bin\ is a bit misleading. I prefer using references in projects. So instead of compiling subproject into ..\bin\ just add a reference to it in the root project and it will get compiled (or more accurately) copied in the root's bin folder.
# July 5, 2006 8:03 AM

sujitha said:

i want some projects in asp.net .can u help me
ur project was so nice
congrates
# July 5, 2006 8:10 AM

Chad said:

Thanks for this.  I have been looking for resources on creating subprojects using the new VS 2005 model for some time now but have found almost nothing in this area. I am anxiously awaiting your next two parts!
# July 5, 2006 9:49 AM

Steve Hebert said:

I did this with VS2003 a few years back.  Unfortunately, I ran into a problem with Windows XP Embedded.  It turns out the html header sent back from XPE's IE caused a hickup in the .NET pipeline.  We reverted to top-level projects to work around the problem.  

I opened a ticket with MS support back then and they verified.  You may to double check if that was fixed - it would be nice to know.  It would be nice to know if this was fixed in .Net vs. XPE - XPE machines tend to live on islands and not get updated as often as other boxes.

-Steve
# July 5, 2006 10:39 AM

scottgu said:

Hi Imran,

If your root project is referencing the sub-projects, then you should go ahead and create a reference from it to them.

However, if your sub-projects are referencing the root project, you'll want to use the ..\bin approach Omar outlined above.

Hope this helps,

Scott
# July 5, 2006 2:48 PM

WebDevTools said:

Hello Imran,

Doing this type of componentization is not well suited to the default "website" model, so I would recommend using "web application project" add-in for it.

As for accessing resources in the root project from a sub-project, I will be explaining that in my next blog post.  I'll try to have that out later this week.
# July 5, 2006 2:48 PM

WebDevTools said:

Hello Markoh,

You are right, creating a project reference in the root project to the various sub-projects does result in the DLL getting copied into the root project's \bin folder.  This technique works and can also be used.

The main reason I recommended changing the sub-projects output path was because it doesn't result in two copies of each sub-project's output DLL (one the \bin of the sub-project and one in the \bin of the root project).
# July 5, 2006 2:52 PM

Tejas said:

I don't see this option "Complie" so I can't change the settings.

Under the “Compile” page change the “Build output path” to “..\bin\”.

Any help?
# July 5, 2006 4:48 PM

WebDevTools said:

Hello Tejas,

I use VB in my example.  If you are using C#, then the tab for the Build output path settering is labeled "Build".
# July 5, 2006 9:34 PM

samstapin said:

Because or until Commerce Server 2007 is released we are tied to VS 2003.

Will this approach work in VS 2003?
# July 7, 2006 8:46 AM

Amit said:

Omar,
I work at a Financial Institution and we act as an ASP (App. Service Provider) of LOS (web-based Loan Origination System). We have close to 140+ web application projects each for every client.

If I take this approach of sub-projects and if I make a change in a code-behind of aspx pages in one of my sub-projects will it re-compile the entire project or can I re-compile just  the sub-project?
# July 7, 2006 11:49 AM

WebDevTools said:

Hello samstapin,

Yes this approach works in VS2003 although the specific steps to set it up are different.

-Omar
# July 7, 2006 4:49 PM

Polo Lee said:

Hi.

This is a greate ideal, but one issue is,
If I want to reuse the root project's ASCX web control, there is no way to review the ascx design in subproject's page, even when run time, the ascx works fine....
# July 10, 2006 4:45 AM

WebDevTools said:

Hello Polo,

In my next part which I plan to post shortly, I'll show how to use an ASCX in the root project from a sub-project.  There is a limitation on design view not displaying it fully, however at run-time it should work fine.

--Omar
# July 10, 2006 1:46 PM

Dom said:

In VS 2003, I remember that I didn't need to create a seperate WAP. I just made a sub folder and createed .aspx pages in that. When compiling the project, the sub pages were compiled into the root bin.

So, with VS 2005, I have to make a new WAP project within the existing one?

One other way is to make two seperate WAP and copy the .dll's into the applicable "bin" folders of the virtual folders in IIS (one being a sub folder).
# July 11, 2006 7:05 AM

Rich said:

Thanks for the information.  it has answered a lot of questions i was asking myself, regarding setting up a project with sub projects.  One thing though.  i would like to set this up on a remote server, rather than have the files reside on my local workstation.  is this possible?
# July 13, 2006 10:41 AM

Michel said:

Hello Omar,

Does this structure works with Visual Web Developer Express?
I look for infoormations about VWDExpress "limitations". Is it possible to have solutions (or an equivalent) like .sln in VS2003? Or it is necessary to use another version?
# July 20, 2006 2:45 AM

WebDevTools said:

Hello Dom,

A subproject is not required by any means.  You can still create subfolders in a WAP project and put ASPX pages in them just like VS2003.  The primary reason to do a subproject is if you want pages in a sub-folder to compile into a different assembly.
# July 21, 2006 1:48 PM

WebDevTools said:

Hello Rich,

WAP projects only support development on a local server.  I will be adding a post soon about how to do sub-project using the built-in ASP.NET develpoment server.  That might be a usable option for you if you are unable to put IIS on your local machine.
# July 21, 2006 1:50 PM

WebDevTools said:

Hi Michel,

The WAP project option only works with Visual Studio Std and higher.  You can however use the default "Website" option in VWD Express which gives the core functionality needed to develop ASP.NET apps.  As well, VWD Express does support solutions, in that you can have mutliple "Websites" in a solution.

-Omar
# July 21, 2006 1:52 PM

Chad Lee said:

How would you use this sub-project architecture in conjunction with WDP?  Would you attach the web deployment project to the Root Project alone or would you attach 2 wdp's to the root and sub-project each?  What are the consequences/side effects of using WDP with this architecture?

Also, where are the next two parts?  :)
# July 24, 2006 4:48 PM

Baishakhi said:

Hello Mr.Khan,

I recently saw your post and found it great for starters. I am also a starter and I am working in a similar application. But my approach has been a little different. Instead of creating a web application as a project  I have created a blank solution. And added to it other web application projects as and when required.

Is the approach right? If not,then what is wrong with it?

If you can , could you answerme at baishakhibanerjee@yahoo.com
# July 28, 2006 2:02 AM

Your Websites, Our Passion! said:

This is the Part 2 of a 3 part series on using sub-projects with the Web Application...
# August 15, 2006 10:55 PM

ScottGu's Blog said:

One scenario that many large development teams often ask me about is whether it is possible to split
# August 16, 2006 3:54 AM

Ron A. Buckton said:

Omar Khan, GPM for the VS 2005 web tools has posted a lengthy example of how to create a partitioned...
# August 16, 2006 8:50 AM

Martin said:

Thanks for this post, it will be very useful. One question though, what happens with the "Themes" if we delete the web.config file. I thought that the line "<pages theme = "MyThemeName" />" was important in the "<system.web>" section in order to have my web application compiled with my theme definitions. Is there a way to link to another web.config file? ... or am I just missing something since the beginning?
# August 16, 2006 9:45 AM

白开水 said:

在ASP.Net开发中,我们通常需要将一个大的Web项目拆分成几个小的Web项目,这样做的优点是:使项目更加清晰明了,开发人员相互不受影响;其次,增强了项目的伸缩性,我们可以根据需求部署不同版本的子项...
# August 17, 2006 2:39 AM

Eladio said:

Hello Omar,

On the root project, is there a way for the root project to self discover the sub-project.

I guess the goal is to have a root project but not to have a reference to the sub projects.  

The root project would look in a sub directory under the root project for dll's and automatically load them.

Thanks,

Eladio
# August 17, 2006 5:58 PM

Ian Suttle said:

I was doing a similar approach with 2003.  An additional benefit for changing the output path is to avoid referencing new WAP projects after initial deployment.  If you were to reference the sub project from the root and release it, then later add another sub project, you would have to alter the root project again.  That definitely isn't a desired scenario in a large application where the purpose of a sub project is to segregate workload or minimize code affected in a single project release.
# August 20, 2006 7:07 PM

John said:

thanks it really helped

http://www.mevx.net
# August 22, 2006 2:33 AM

New bee said:

Hi all,
I have splitted the project. Very Nice.
I also splitted the user web controls as a project.  Now i cant use the controls in other sub projects.
# August 29, 2006 2:43 AM

steveculshaw said:

Thanks for this information, really useful. Keep up the good work

Cheers,
Steve C.
# August 29, 2006 7:05 AM

WebDevTools said:

Hello New bee,

Please see part 2 of this post for information about user controls across projects.

http://blogs.msdn.com/webdevtools/archive/2006/08/15/701642.aspx

--Omar
# August 29, 2006 1:44 PM

Ryan Reid said:

In our model, we can't reference the sub-project in the main project because it isn't known at design time. I've found that if you are dynamically loading controls, you HAVE to have the assembly in the MAIN /bin/ path and not in a private path. Is there any workaround to this?
# August 29, 2006 5:25 PM

Ashish Agrawal said:

Why we have 2 diffrent attributes in @Page for WAP and WSP. WSP used CodeFile where WAP use CodeBehind. Is there any functional requirement behind this? Can't both be same?
# September 1, 2006 2:11 AM

Ashish Agrawal said:

I got the answer my self. WAP and WSP can't share same attribute. If they share, it will result in runtime error becuase WSP will create assembly for code, which is already included in another assembly ( Generated as WAP ).

Try to get single Attribute will require to have a big change in ASP.NET compiler it self.

Thanks for the thread, it helped me to get some answers.
# September 1, 2006 8:38 AM

inventive title said:

Omar Khan, GPM for the VS 2005 web tools has posted a lengthy example of how to create a partitioned
# September 22, 2006 5:39 PM

Alan said:

OK - how do I get around " The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file. "?
# September 26, 2006 9:22 AM

Vinix said:

The value "..\bin\" can not be saved and restored to "bin\" after pressing "Apply". Any idea why this happened?

# October 3, 2006 5:06 AM

Rob said:

As per Amit:

...We have close to 140+ web application projects ....

If I take this approach of sub-projects and if I make a change in a code-behind of aspx pages in one of my sub-projects will it re-compile the entire project or can I re-compile just  the sub-project?

Amit

********************************************

I have the same question. If I make changes to one project will I have to re-compile the whole solution including all the sub-projects?

Thanks

# November 14, 2006 11:12 AM

Your Websites, Our Passion! said:

This is the Part 3 of a 3 part series on using sub-projects with the Web Application Projects add-in

# November 27, 2006 7:38 PM

WebDevTools said:

Hello Rob,

Yes, if you make a change to a sub-project, the other projects will not get compiled.  Breaking a very large app into smaller compilation units is one benefit of this approach.

# December 5, 2006 2:42 PM

David said:

I just installed the VS 05 SP1. I also installed the WAP add in. I think I got things set up right. Both .dlls are in the MyLargeWebApp\bin. When I run the root page it works fine. When I run the sub project I get the following error on Line 1:

Server Error in '/' Application.

--------------------------------------------------------------------------------

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type 'SubProject1._Default'.

Source Error:

Line 1:  <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="SubProject1._Default" %>

Line 2:  

Line 3:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Does anyone have any suggestions?

Thanks,

David

# January 17, 2007 10:09 PM

Frank said:

Can you please offer some advice on deploying the sub project? The publish feature compiles the entire sub project into it's own bin folder. I dabbled with Web Deployment Projects but don't yet understand them completely or if they are capable of accomplishing what I need. Maybe another article?

Thanks,

Frank

# January 18, 2007 10:22 AM

Kevin said:

Hi all , very nice site! Thank You !

# February 11, 2007 10:10 PM

Espresso Fueled Agile Development said:

Earlier today, I posted to the WCSF CodePlex Community Site a new code-only guidance package, Web Application

# March 26, 2007 9:58 PM

Jester said:

I have a Sub-Project set up to use ASP.NET AJAX. My Master file and Web.config file are in the root project. My file lookup.aspx that implements the master file is in the Sub-Project. All references to the AJAX library are included in both root and sub projects. My problem is that when I start trying to include <asp:updatepanel in the lookup.aspx the designer complains that it doesnt know what an update panel is and subsequently nothing is added to the designer file.

# April 9, 2007 12:06 PM

WebDevTools said:

Hi Jester - can you verify that an update panel works properly in the root project?  If that works send me an email (omark-at-microsoft-dot-com) and i'll see if I can help understand what is happening.

# April 9, 2007 8:00 PM

Mark B said:

I presented this at my company and was told (after working on this for a week!) that the all of the sub-apps would be running in the same process, so if an unhandled error occurred in one sub-app it could cause the application pool to become corrupt and force a recycling that would affect every sub-app. This could cause a loss of all session data in every app.

Since i am a noob I have no idea if this true. Help!

-Mark

PS-I noticed that this structure allows you to share session variables between applications

# May 1, 2007 12:50 PM

Jelle Ossewaarde said:

I encounter that the subproject throws an error on AJAX: "Element name is not a known element. This can occur if there is a compilation error in the Web site." I use the method in which after a build the ascx are copied into the root bin : http://webproject.scottgu.com/visualbasic/usercontrols/usercontrols.aspx

Jelle

# May 2, 2007 6:43 PM

Jelle said:

I have same problem as with AJAX, but then with the controltoolkit.

Error 2 The name 'MyAccordion' does not exist in the current context Error 3 Element 'Accordion' is not a known element. This can occur if there is a compilation error in the Web site.

<%@ Control Language="C#" Inherits="V4A.Modules.PNGT.ViewPNGT" CodeFile="ViewPNGT.ascx.cs" AutoEventWireup="true" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="System.Web.UI.WebControls.WebControl" TagPrefix="ajaxToolkit" %>

<div class="demoarea">

<ajaxToolkit:Accordion id="MyAccordion" runat="server" TransitionDuration="150" FadeTransitions="true" AutoSize="None" HeaderCssClass="pnavH">

</ajaxToolkit:Accordion>

</div>

# May 2, 2007 7:01 PM

Jelle said:

http://ajaxcontroltoolkit.com/Walkthrough/Setup.aspx

The designer did not have the items in the toolbox. A pitty, but solved.

# May 2, 2007 7:42 PM

Luciano Panaro said:

Introduction The recent release of WCSF 1.1 includes support for the Web Application Projects . Not only

# June 22, 2007 9:12 AM

Jacky_xu said:

本周ASP.NET英文技术文章推荐[11/26-12/02]

提醒:若朋友们想对英文文章进行翻译,则首先需要征得原作者的同意,以免日后导致无谓的版权纷争。以下内容节选自《中华人民共和国著作权法...

# October 29, 2007 10:47 PM
New Comments to this post are disabled
Page view tracker