Tuesday, February 22, 2011

Converting a website project to a web application project

Because I had some trouble with source control integration of a website project I decided to convert it back to a web application. But how do you do this? Turns out that this is not a one step process.

The best strategy for converting an existing Web site project is to first create a new, blank Web application project in a separate directory. This avoids changing any part of the existing Web site project files. It also enables you to copy existing functionality into the new Web application project.

Step 1 -  Create a new Web application project
  1. In the File menu, click New, and then click Project.
  2. The New Project dialog box is displayed.

  3. 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.

  4. Select ASP.NET Empty Web Application.

  5. Type values for Name, Location, and Solution Name, and then click OK to create the Web application project.

Step 2 -Add required references to the Web application project
  1. In Solution Explorer, right-click References, and then click Add Reference.

    The Add Reference dialog box is displayed.

  2. Select the references that you want to add and then click OK.

  3. 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.

Step 3 - Copy the Web site files to the Web application project
  1. In Solution Explorer, right-click the Web site project and select Open Folder in Windows Explorer.

  2. Select the files of the Web site project to copy.

  3. Right-click the selected files and then click Copy.

  4. In the Web application project, right-click the Web application project and click Open Folder in Windows Explorer.

  5. Paste the Web site project files into the Web application project directory.

  6. In Solution Explorer of the Web application project, click the Show All Files button.

  7. Select the new files in Solution Explorer.

  8. Right-click the selected files and then click Include In Project.

Step 4 - 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 to recursively examine every page, master page, and user control in the project, and to automatically generate a .designer.cs or .designer.vb file for each. Visual Studio also changes the .aspx or .ascx files to use the codeBehind attribute instead of the codeFile attribute. This conversion process also renames the App_Code folder to Old_App_Code.

To convert pages and classes to use partial classes in a Web application project
  1. 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.

  2. Build the project to see whether there are any compilation errors.

For more information, check the MSDN documentation.

3 comments:

deep said...

thanks.it helps me

deep said...
This comment has been removed by the author.
deep said...

thanks