Walkthrough: Converting a Visual Studio .NET 2003 Web Project to a Visual Studio Web Application Project

By converting the Visual Studio .NET 2003 Web project to a Visual Studio 2008 Web application project, you can take advantage of features of Visual Studio 2008. This includes refactoring, class diagrams, test development, and generics. The Web application project model also makes available all the features of ASP.NET 2.0 and later. These include master pages, data controls, membership and logon controls, role management, Web Parts, personalization, site navigation, and themes.

The Visual Studio 2008 Web application project model more closely matches the project model available for Visual Studio .NET 2003 applications. This can be useful if you are converting a Visual Studio .NET 2003 Web project to Visual Studio 2008. For more information about new features, see What's New in ASP.NET and Web Development.

Note

You can create ASP.NET Web application projects using Visual Studio or Visual Web Developer Express.

This walkthrough explains how to convert an existing Visual Studio .NET 2003 Web project to a Web application project in Visual Studio 2008. The Web application project model uses the same conceptual approach as a Web project in Visual Studio .NET 2003. This includes a project file to include and exclude files, and compilation to a single assembly. For more information, see Web Project Conversion from Visual Studio .NET.

Note

To convert a Web site that uses Microsoft Office FrontPage 2003 to a Web application project, first convert the FrontPage Web site to a Visual Studio 2008 Web site project. Then convert the Web site project to a Web application project. For more information, see Walkthrough: Converting a Web Site Project to a Web Application Project in Visual Studio.

Tasks illustrated in this walkthrough include the following:

  • Opening and verifying the Visual Studio .NET 2003 Web project.

  • Backing up the Visual Studio .NET 2003 Web project.

  • Converting the Visual Studio .NET 2003 Web project to Visual Studio 2008.

  • Verifying the Web application project in Visual Studio 2008.

  • Converting code-behind classes to partial classes.

  • Examining and resolving XHTML-compliance issues.

Prerequisites

In order to complete this walkthrough, you will need:

  • Visual Studio .NET 2003

  • Visual Studio 2008 or Visual Studio 2005 Service Pack 1 (SP1) or Visual Web Developer Express

  • .NET Framework version 2.0

Opening and Verifying the Visual Studio .NET 2003 Web Project

Before you convert a project, you should verify that it is working correctly. This will prevent errors during conversion.

To open and verify the Visual Studio .NET 2003 Web project

  1. Open Visual Studio .NET 2003.

  2. In the File menu, click Open File, and then type or browse to the .sln file for the solution that you want to verify.

    Note

    In Visual Studio .NET 2003, the files that make up the project are included in a solution file (.sln).

  3. In the Project menu, click Build Solution.

  4. In the Debug menu, click Start.

  5. Verify that the project runs as expected.

Backing Up the Visual Studio .NET 2003 Web Project

It is a good idea to back up the Visual Studio .NET 2003 solution and project files before you start the conversion process. If any conversion issues occur, you can revert to the Visual Studio .NET 2003 solution.

To back up the project, you copy the project in Visual Studio .NET 2003.

To back up the Visual Studio .NET 2003 Web project before conversion

  1. Open Visual Studio .NET 2003.

  2. In the File menu, click Open File, and then type or browse to the .sln file for the solution you want to back up.

  3. In the Project menu, click Copy Project.

  4. In the Copy Project box, select Destination project folder.

  5. Select a Web access method option. You can use either FrontPage or File share to copy the files.

  6. Select the Include all files in the project folder option and then click OK.

Converting The Visual Studio .NET 2003 Web Project to Visual Studio 2008

Visual Studio 2008 converts the Visual Studio .NET 2003 solution and the project files to use the Microsoft Build Engine (MSBuild) format, which is the project file format in Visual Studio 2008.

As part of the conversion process, Visual Studio 2008 generates an XML-based log file that provides a summary of the conversion and that flags issues. By default, the conversion log file is saved in the same directory as the .sln file. If you have problems when you compile the converted project, you can refer back to the conversion log file.

To convert the Web project to Visual Studio 2008

  1. In Visual Studio .NET 2003, close the solution file.

  2. Open Visual Studio 2008.

  3. In the File menu, click Open File, and then type or browse to the .sln file for the solution that you want to convert.

    The Visual Studio 2008 Conversion Wizard opens.

  4. Click Next, follow the instructions to complete the wizard, and then click Finish.

Verifying the Web Application Project in Visual Studio 2008

After the solution and project files are converted to the Visual Studio 2008 format, you should validate that the application can build without errors and that it runs as expected.

To verify the Web application project in Visual Studio 2008

  1. In Visual Studio 2008, on the File menu, click Open File, and then type or browse to the .sln file for the solution that you want to verify.

  2. In the Project menu, click Build Solution.

  3. In the Debug menu, click Start.

  4. Verify that the Web application project runs as expected.

Common Errors and Warnings

The most common types of errors or warnings that you see during the conversion process are as follows:

  • Conflicts with names that were introduced in the .NET Framework version 2.0.

  • Warnings about obsolete members.

  • Issues that occur when you run the Web application.

To fix naming conflicts, you can remove ambiguity by fully qualifying existing names with a namespace. Alternatively, you can rename the conflicting types and members so that they do not conflict. For more information about naming conflicts, see ASP.NET 2.0 Migration Overview and Namespace Naming Guidelines.

If you see a warning about obsolete members, the warning message will typically suggest alternative members to use. In that case, you can continue to use the obsolete members. However, the members will be removed in the next major release of the ..NET Framework. Therefore, it is a good practice to remove the members and substitute the suggested alternatives.

If you see an error that indicates that a directory listing is denied when you run the Web application, the Web application's virtual directory might not allow its contents to be listed. To fix this issue, in Solution Explorer, right-click the application's start page and then click Set as Start Page. This makes sure that the correct page is invoked when the application runs.

Converting Code-Behind Classes to Partial Classes

In Visual Studio 2008, Web application projects use partial classes for code that is generated by Visual Studio. These classes are stored in a separate file from the code-behind file. By default, the Visual Studio 2008 Conversion Wizard does not create a *.designer.cs file or a *.designer.vb file for Web pages (.aspx files) or user controls (.ascx files). Instead, the code will look and work just like it did in Visual Studio .NET 2003.

Note

The Visual Studio 2008 Conversion Wizard will make the minimum number of changes possible to the code files during the conversion process. This helps create a smooth conversion to a Web application project in Visual Studio 2008.

You can keep the code in the Visual Studio .NET 2003 format. If you do, you must manually update the control field declarations in the code-behind files as you did in Visual Studio .NET 2003. However, to take advantage of the ability to maintain field declarations in generated code, you should update the pages and controls to use the partial-class model. Partial classes make it easier to organize the generated code and custom code for the code-behind files. For more information, see Partial (Visual Basic) and partial (Type) (C# Reference).

To convert the code to use the partial-class model

  1. Make sure the code compiles without errors.

  2. In Solution Explorer, right-click the project name and click Convert to Web Application.

    This command iterates through each page and user control in the project. It moves all control declarations to a .designer.cs or designer.vb file. It also adds event handler declarations to the server-control markup in the .aspx and .ascx files.

    Note

    You can use the Convert to Web Application command on individual pages. You might do this first on a few pages so that you can see the changes that were made for each page before applying the changes to the whole application.

    You cannot undo the effect of the Convert to Web Application command. The best method for restoring the changes is to restore from a backup of the Visual Studio .NET 2003 project, and then to re-run the Visual Studio 2008 conversion as described earlier.

  3. When the process has finished, check the Task List window to see whether any conversion errors are reported.

  4. If the Task List displays errors, right-click the relevant page in Solution Explorer and select View Code and View Code Gen File to examine the code and fix problems.

    Note

    Errors and warnings that appear in the Task List window persist between Visual Studio sessions. After you have fixed errors listed in the window, you can clear items from the task list.

  5. Recompile the project to make sure that it compiles without errors.

From this point, when you add new pages to the Web project, by default the pages will use the partial-class template. For more information, see ASP.NET 2.0 Migration Overview.

Examining and Resolving XHTML-Compliance Issues

By default, Visual Studio 2008 generates and validates XHTML-compliant markup. This helps you build Web applications that are standards compliant and helps minimize issues with browser-specific rendering. By default, Visual Studio .NET 2003 does not generate XHTML-compliant markup. Therefore, after you convert the Web application to Visual Studio 2008, you might see validation and rendering issues with pages that were created in Visual Studio .NET 2003.

Note

Validation errors are informational only and are flagged as warnings. Validation errors do not prevent a page from running.

If you want to see HTML validation errors as you did in Visual Studio .NET 2003, switch the HTML validation setting from XHTML Transitional to Internet Explorer 6.0. Internet Explorer 6.0 was the default setting in Visual Studio .NET 2003 for HTML validation. For more information, see How to: Select Validation Schemas for HTML Editing in Visual Web Developer.

You can also add the following section to the project's Web.config file, which causes ASP.NET to render legacy (non-XHTML compliant) markup from server controls:

<system.Web>
  <xhtmlConformance mode="Legacy" />
</system.Web>

This avoids the small rendering differences you might see between pages displayed using ASP.NET 1.1 and using ASP.NET 2.0. Note that you should use the xhtmlConformance mode change only to resolve any conversion issues. When the Web application project is running correctly, remove the legacy configuration setting. For more information, see ASP.NET and XHTML and ASP.NET 2.0 Migration Overview.

See Also

Tasks

How to: Upgrade Projects Created in Earlier Versions of Visual Studio

Concepts

Web Project Conversion from Visual Studio .NET

ASP.NET 2.0 Migration Overview

ASP.NET Web Page Code Model

ASP.NET and XHTML

Reference

Partial (Visual Basic)

partial (Type) (C# Reference)

Partial Classes and Methods (C# Programming Guide)

Visual Studio Conversion Wizard

Other Resources

Namespace Naming Guidelines