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
- 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 Empty Web Application.
-
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
-
In Solution Explorer, right-click References, and then click Add Reference.
The Add Reference dialog box is displayed.
-
Select the references 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.
Step 3 - Copy the Web site files to the 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 then click Copy.
-
In the Web application project, right-click the Web application project and click Open Folder in Windows Explorer.
-
Paste the Web site project files into the Web application project directory.
-
In Solution Explorer of the Web application project, click the Show All Files button.
-
Select the new files in Solution Explorer.
-
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
-
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.
For more information, check the MSDN documentation.