Sunday, March 18, 2012

Separate Web application into multiple projects

I read a number of blogs on how to do this. Most of them were for VS 2005 but none for VS 2010 (It doesn't matter though). Also all the blogs involved using IIS instead of IISExpress which we use for development. This is the link that was the most useful http://support.microsoft.com/default.aspx?scid=kb;EN-US;307467

It really doesnt matter what folder structure you use or where the sln file is placed. This is the structure that we have.

Red Line: Folder structure
Blue Line: Project References

You can have multiple Child Web Application. We have 3 child web applications currently.

These are the steps to create the project structure:

  1. Create the parent web application. 
  2. Create child web applications.
  3. If you are converting an existing web site to web application and moving your App_Code outside of the web application then create a Class Library project and move everything from App_Code in the website to the new App_Code class library project.
  4. Add reference of App_Code class library project to all web application. (If there are any web applications you can surely avoid adding this reference)
  5. Create Common User Controls library (if needed). This can even include Web User Controls.
  6. If you have separated your User Controls in step 3 (Common User Controls child Web App in the diagram) into a separate web application then you will have to add the reference of this project in every child project that uses this User Controls.
  7. Add reference for each child web application in parent web application. If parent web application uses the user controls even add reference of Common User Controls in parent we application.
  8. If your web config includes tagprefix then ideally you should keep the web.config. This gives you two advavatages: 1. You wont see any annoying error messages on aspx pages coz visual studio wont be able to find the reference for the tagprefix. 2. If you have web deployment projects it wont compile.

Steps to build and run the project:

There are two ways in which we can do this. With either treating the child web applications as virtual folders in IISExpress or having a post build step to copy .aspx and .ascx files to where they were originally.

Case 1: Virtual folders (My way)

In applicationhost.config file for IISExpress find your site. This is what visual studio adds for parent web application:


This is what you will have to add for each of your child projects:


Case 2: Post build step

I have never tried this. But it should work. In the post build step of each child web application project add a copy step to copy in the parent directories physical location. You wont need to make any changes in the IISExpress configuration.

I think I have covered all the steps that I know. :)

No comments:

Post a Comment