
Creating a New Visual Studio 2008 Web Application Project
The best strategy for converting an existing Visual Studio 2005 Web site project is to first create a new, blank Visual Studio 2008 Web application project in a separate directory. This avoids changing any part of the existing Web site files. It also enables you to copy existing functionality into the new Web application project.
You can add the new project to an existing solution, which is ideal when you have several class-library projects that you want to use. Alternatively, you can start a new instance of Visual Studio and create a new solution and project.
To create a new Visual Studio 2008 Web application project in a new solution
In Visual Studio 2008, close all open solutions.
In the File menu, click New, and then click Project.
The New Project dialog box is displayed.
In the Project types section of the New Project dialog box, expand the language that you want to use, and then select Web to display the Web-related templates.
Select ASP.NET Web Application.
Type values for Name, Location, and Solution Name, and then click OK to create the Web application project.
After the project has been created, delete the Default.aspx and Web.config files that are created automatically.
Setting Project References
If the Visual Studio 2008 Web site project requires additional project or assembly references, you can add them to the Web application project. You can see the list of default references with new Visual Studio 2008 Web application projects under the References node in Solution Explorer.
Note: |
|---|
To help prevent errors, before you convert the project files, add references to the Web application project for assemblies that existed in the Bin folder. See the following procedure for more information about how to add references.
|
For more information about references, see Project References.
To add references to a Visual Studio 2008 Web application project
In Solution Explorer, right-click References, and then click Add Reference.
The Add Reference dialog box is displayed.
Select the reference that you want to add and then click OK.
In Solution Explorer, right-click the Web application and click Build.
Visual Studio builds the project and verifies that any project-to-project references are working.
Copying Files to the Web Application Project
The easiest way to add your existing files is to copy the files from a Visual Studio 2008 Web site project directory to the Web application project directory.
Note: |
|---|
If the Data Source Configuration Wizard starts during the copy process, click
Cancel in the wizard's dialog box and let the rest of the files be copied.
|
To copy a Web site project to a Web application project
In Solution Explorer, right-click the Web site project and select Open Folder in Windows Explorer.
Select the files of the Web site project to copy.
Right-click the selected files and select Copy.
In the Web application project, right-click the Web application project and select Open Folder in Windows Explorer.
Paste the Web site project files into the Web application directory.
In Solution Explorer of the Web application project, click the Show All Files button,
Select the new files in the Solution Explorer.
Right-click the selected files and then click Include In Project.
One difference between a Visual Studio 2008 Web site project and a Visual Studio 2008 Web application project is that the Web site project model dynamically generates the tool-generated partial class.
After you copy the files from the Web site project to the Web application project, you will notice that the code-behind files for each page and user-control are still associated with the .aspx, .master, and .ascx files. No .designer.cs or .designer.vb files have been generated. As part of the next step, you convert these pages to save their partial classes in a .designer.cs or .designer.vb file.
Converting the Project Files
Visual Studio includes an option to convert pages and classes in Web application projects to use partial classes. Partial classes are used to separate the markup in a page or user control code-behind code. These designer-generated classes are stored in a separate file from the code-behind file.
The conversion process causes Visual Studio 2008 to recursively examine every page, master page, and user control in the project, and to automatically generate a .designer.cs file for each. Visual Studio also changes the .aspx or .ascx files to use the codeBehind attribute instead of the codeFile attribute. This command also renames the App_Code folder to Old_App_Code.
To convert pages and classes to use partial classes in a Web application project
In Solution Explorer, right-click the root project folder that contains the pages and classes that you want to convert, and then click Convert to Web Application.
Build the project to see whether there are any compilation errors.
If you see errors, the two most likely causes are as follows:
An assembly reference that is missing and that must be added to your project.
An issue with a dynamically generated type, such as the Profile object or a typed dataset.
If you are missing an assembly reference, open the reference manager and add it. If you are using a dynamically generated type, see Converting Declarative Typed Datasets and Converting Profile Object Code later in this topic.
Because ASP.NET 2.0 dynamically compiles all classes in the App_Code folder, you should not store classes in the folder that you compile as part of your Visual Studio 2008 Web application. If you do, the class will be compiled two times. The first time will be as part of the Visual Studio 2008 Web application project assembly, and the second time will be at run time by ASP.NET. This can cause a "could not load type" exception, which occurs because there are duplicate type names in the application.
Instead, store class files in any folder of your project other than the App_Code folder. This is done automatically by the Convert to Web Application command, which renames the folder to Old_App_Code.
Running the Web Application Project
You can now compile and run the application. By default, Visual Studio 2008 uses the built-in ASP.NET Development Server to run the site. Alternatively, you can configure the project to use Internet Information Services (IIS). To manage Web application project settings, right-click the project and then click Properties. You can then select the Web tab to configure these run-time settings.
For more information, see Web Page, Project Designer.