If you don’t want to read about why I tried to use the Web Application Project model, please “fast forward” to How to set up multiple WAPs in one solution.
Preface
What is the Web Application Project? Plus there are some good pointers in Scott Guthrie’s blog.
For a client of mine, I am currently working out a major best-practice guideline for developing reusable .NET 2.0 programs. Their situation calls for a program design that makes it as easy as possible to reuse modules on multiple websites and on multiple rich clients. So I chose an approach that is a mixture between MVP and software cells to make it easier to reuse a lot of code between a Web App and a Windows Forms App. Unfortunatelly that still calls for duplicated code between multiple web apps, since the Views (Custom Controls) will reside inside the Web Site Project. Therefore it will get increasingly cumbersum to share modules between different web solutions. I thought back to when I used VS 2003 and thought it was really unfortunate that Microsoft changed the web project’s look and feel. Why couldn’t I create multiple web projects, each representing all of one module’s views. I remembered having blogged about WAP a while back – even though for a different reason. It is an optional project style released by Microsoft that provides the same project, build and compilation semantics as the web project model known from VS 2003. Using WAP it is possible to use multiple projects each containing custom controls. Using WAP, it should be possible to use a (simplified) project tree like this:
- Com.Hertkorn.Infrastructure.Cells.Forum (Class Library)
containing Presenter, BLL and DAL, the M and P part of MVP - Com.Hertkorn.Website.Views.Forum (Web Application Project)
containing Custom Controls, the V part of MVP for websites - Com.Hertkorn.Forms.Views.Forum (Windows Control Library)
containing the V part of MVP for windows forms
Yeah, I know this a very crude representation of the actual assembly structure needed for real world MVP and Cells, but I made it simple enough to stress the main point: Now the multiple web solutions only need to reference Com.Hertkorn.Infrastructure.Cells.Forum and Com.Hertkorn.Website.Views.Forum in order to use the forum module. And Windows Applications use Com.Hertkorn.Infrastructure.Cells.Forum and Com.Hertkorn.Forms.Views.Forum. Therefore the duplicate code is reduced to a minimum.
But I had some trouble setting it up using VS 2005. I contacted Scott and he helped me through the process and I got it to work. For anybody else who is interested in the process, I decided to write it down. Even though right now I will not be able to use it. Unfortunatelly the May release of WAP does not render Custom Controls inside the designer that are contained in a different project. This issue will be fixed in the SP1 of VS 2005. That means there will still be no way around WSP and duplicated code til then.
How to set up multiple WAPs in one solution
Now let’s get to the good stuff. This is mostly from an email Scott was kind enough to forward me. And even better – he allowed me to blog about it using his stuff. Thanks again for that, Scott!
As I said before – but I’ll repeat it here for all of you who skipped the preface. Setting up multiple WAPs can be done with the current version (WAP May 2006 + VS 2005 no SP), but there are some limitations:
- It only works for IIS webs.
- Design view does not render controls outside the WAP project (to be fixed in SP1)
If you’d like to setup this up to see how it works here are the steps:
- Create a new Web Application Project e.g. C:\MyProjects\MainWeb
- Create a virtual directory pointing to this location.
Project Properties/Web Tab/Server Section
Check “Use IIS Web server”
Edit Project URL to http://localhost/MainWeb
Push the “Create Virtual Directory” button
(these steps will create the VDIR for http://localhost/MainWeb and map it to C:\MyProjects\MainWeb) - Add a new Web Application Project to the solution
C:\MyProjects\MainWeb\SubWeb1
(note this will not be a true IIS sub-web, it’s just a folder in the MainWeb) - Change the build output path to be the bin folder of the MainWeb
Project Properties/Build Tab/Output section.

- Change the subweb to be a folder under the same VDIR as the MainWeb
Project Properties/Web Tab/Server Section
Check “Use IIS Web server”
Edit Project URL to http://localhost/MainWeb/SubWeb1

- Save All, close and re-open the project properties
You should see application root URL set to http://localhost/MainWeb
This tells you that WAP is correctly detecting the subweb relationship.
There is only one IIS Web application in this model. http://localhost/MainWeb mapped to c:\MyProjects\MainWeb. However with this configuration the site is factored into several WAP projects that build into a common bin in the MainWeb.
To build and run a SubWeb project you must have the latest assemblies from the other projects in the MainWeb bin. Building the solution will take care of this for you.
The main advantage of this configuration is that it allows you to build the SubWeb folders independently into separate assemblies. This works great until you start creating dependencies by consuming controls from other SubWebs. Some sites I’ve seen have created a separate project with all the Controls to avoid this issue.
Depending on your scenario this maybe a good model. The alternative is to create this as a single project, which also works quite well.
The major disadvantage of using this approach is that the designer will not render controls outside it’s immediate project so the Control Project design above won’t render in design view. Unfortunately the WAP developers won’t be able to fix this scenario until Visual Studio SP1 later in the fall.
Tweet this