IN THIS TASK
- Single Project Method
- Multiple Project Method
- Make Multiple Visual Studio .NET Projects Participate in the Same Web Application
You may find it useful to separate a large Web application project into multiple projects for team development of ASP.NET Web applications in Microsoft Visual Studio .NET. Microsoft recommends that you use source control software, such as Microsoft Visual SourceSafe, in all scenarios.
Developing a large Web site frequently involves several developers. These developers must be able to work on specific sections of a Web application without interfering with one another and yet still be able to use each other's work as the project progresses. To do this, you can use a single project in a Visual Studio .NET solution. You can also separate a Web application into multiple projects by dividing the development project into units to make development easier.
You can develop Web applications in single project or multi-project Visual Studio .NET solutions. The advantages and disadvantages of each method are outlined in the sections to follow.
- Microsoft Windows 2000 Professional, Microsoft Windows 2000 Server, Microsoft Windows 2000 Advanced Server, or Microsoft Windows XP Professional
- Microsoft Internet Information Services (IIS)
- Microsoft .NET Framework
- Microsoft Visual Studio .NET
- Creating Visual Studio .NET Web applications
The advantages of the single project method are as follows:
- This method is easy to implement. You create a single Web application project in Visual Studio .NET, and then you add application items to it.
- For smaller Web applications, a single Visual Studio .NET project is easy to manage.
- Visual Studio .NET directly supports this method. You do not have to take special steps to make this method work.
- Because the whole project is built into a single assembly, you do not need references between multiple assemblies.
- Large Web applications are difficult to manage as a single unit.
- Every time you want to build your work, even for small code changes, you must build the whole project. For large projects, this can be very time consuming and can make development less efficient.
Visual Studio .NET does not directly support this method because Visual Studio .NET Web projects are always created in their own IIS application root directories with their own assemblies. IIS Web applications cannot span multiple IIS application root directories.
Additionally, you cannot use resources in one root directory from other root directories in Visual Studio .NET. It is difficult to create a single application from multiple projects if these applications cannot share resources.
To resolve these problems, you can use the procedure in the Make Multiple Visual Studio .NET Projects Participate in the Same Web Application section so that multiple Visual Studio projects share the same IIS application root directory.
The advantages of the multiple project method are as follows:
- It is easier to manage smaller units of a large Web application.
- You can build each project separately from the other projects, which shortens the build times during development.
- You can divide a large Web application into logical units and have these units share common resources, such as controls.
- Visual Studio .NET does not directly support this method. You must perform additional steps so that separate Visual Studio .NET projects participate in the same Web application.
- Assemblies that access each other's resources must set references to each other. Visual Studio .NET does not allow circular references.
- This method is not ideal for small Web applications. For small Web applications, it is more complex to manage multiple projects than to manage a single project.
To make the Visual Studio .NET projects participate in the same Web application, you must complete four main steps:
- Create the main project in a directory that is the root directory for the whole application.
- Create the child projects in subdirectories of the root directory in the same Visual Studio .NET solution.
- Remove the Web applications that Visual Studio .NET creates for the child projects through IIS.
NOTE: Because Visual Studio .NET does not allow you to create or to work with multiple Web applications in the same physical directory, you must create the various projects that make up your application in separate directories.
- To deploy the projects to individual development computers, copy the application directory structure to those computers, and then create an IIS application root directory for the main project directory.
- Start Visual Studio .NET.
- On the File menu, point to New, and then click Project.
- In the New Project dialog box, click the language that you want to use under Project Types, and then click ASP.NET Web Application under Templates.
- In the Location text box, replace the WebApplication# default name with MainWeb. If you are using the local server, you can leave the server name as http://localhost. The Location box should then appear as follows:http://localhost/MainWeb
- For each child project, right-click the solution in the Solution Explorer window, point to Add, and then click New Project.
- In the Add New Project dialog box, click ASP.NET Web Application under Templates.
- In the Location text box, type http://localhost/MainWeb/<subwebname>. This creates a child project named <subwebname> in a subdirectory of the root application directory.
- Click OK.
- Delete any files that are not needed for a non-application root directory from the project. Specifically, delete the Global.asax and the Web.config files. This child project will rely on the Global.asax and the Web.config files from the main project.
- If the child project will only contain shared resources, such as user controls, delete the WebForm1.aspx file.
- Build the solution.
- Click Start, point to Programs (or All Programs in Windows XP), point to Administrative Tools, and then click Internet Services Manager.
- Locate your main Web application and the child Web projects that you want to remove.
- For each child project, right-click the Web application node, and then click Properties.
- On the Directory tab, click Remove, and then click OK.
IMPORTANT: Do not click Delete. This can permanently delete the corresponding file directory and your project files.
- In Solution Explorer of the main Web application, right-click References, and then click Add Reference.
- In the Add Reference dialog box, click the Projects tab.
- Select the child projects, and then click OK.
There are many options for deployment, and it is beyond the scope of this article to describe each option. For example, you can deploy built versions of some of the source files in large Web applications to avoid bringing in many source files. Any references to local projects must be project references. If you want to drag ASP.NET user controls from another project onto a Web Form, the project that contains the user control must exist on your computer and in your solution.
For smaller ASP.NET Web applications, you can combine all of the projects. A good way to do this is to click Copy Project on the Project menu in Visual Studio .NET. You can also copy the project files to a computer.
To deploy the multi-project Web application to a development computer, follow these steps:
- Copy the whole directory structure that you created in the previous steps to a development computer.
- Make the directory that contains the root project an IIS application root. The easiest way to do this is to use the File System Explorer (if you are working with the NTFS file system) as follows:
- In the File System Explorer, locate the root directory of the Web application.
- Right-click the directory, and then click Properties.
- In the Properties dialog box, click the Web Sharing tab, and then click Share this folder.
- In the Alias box, type the name of the Web application, and then click OK.
- Click OK to close the Properties dialog box.
- Make sure that all of the user identities who will be using the Web application (such as the IUSR account) have access to the directories.
- Build the solution.