Part 1 of 3: Creating sub-projects in IIS with Web Application Projects

Part 1 of 3: Creating sub-projects in IIS with Web Application Projects

Rate This
  • Comments 57

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

Leave a Comment
  • Please add 1 and 5 and type the answer here:
  • Post
  • 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
  • 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.
  • i want some projects in asp.net .can u help me
    ur project was so nice
    congrates
  • 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!
  • 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
  • PingBack from http://codebetter.com/blogs/steve.hebert/archive/2006/07/05/147117.aspx
  • 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
  • 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.
  • 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).
  • 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?
  • 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".
  • Because or until Commerce Server 2007 is released we are tied to VS 2003.

    Will this approach work in VS 2003?
  • 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?
  • Hello samstapin,

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

    -Omar
  • 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....
Page 1 of 4 (57 items) 1234