With the release of Visual Studio 2013, Microsoft has released a new template called “One ASP.NET” which allows the creation of a combined ASP.NET Web Application project which can utilize Web Forms, MVC and Web API.
Not all development teams have transitioned over to using Web API in their projects, but a frequent request is to combine both Web Forms with ASP.NET MVC.
In order to migrate from an existing ASP.NET Web Forms project over to the One ASP.NET Web Application project type, you will need to dissect the One ASP.NET Web Application project and leverage your knowledge of MSBuild in order to properly copy over all of the necessary elements.
Here is the default entire One ASP.NET Web Application project in its entirety:
Now, for the dissection of the project:
First of all, you will need to make sure that you copy over the appropriate ProjectTypeGuids elements:
The remainder of the editing work involves reviewing the individual ItemGroups for content to copy over:
- You will need to copy over any ItemGroup elements that covers any required References
- You will need to copy over any ItemGroup elements that create the App_Start, Views, Content, Controllers and Models directories.
- You will need to copy over any ItemGroup elements that include any required Scripts in the Scripts directory.
Next, of course, you will have to manually copy those files and folders referenced above (App_Start, Views, Content etc.) into your Project directory using Windows Explorer. In addition, you will need to copy over the packages directory (specified through a relative file path in the Visual Studio project). Because NuGet is used for many of the assembly references in the One ASP.NET Web Application project, these assembly references are stored in the package directory that is created while using NuGet Package Manager.
If all the appropriate files and folders have not been copied over, Visual Studio will not be able to load the project since it will not be able to find the References or Content elements referred to in the project file.
Once you have finished manually editing your Web Forms Web Application Project file, you should be able to save it and re-load the file in Visual Studio 2013. If the project loads successfully, you can begin using it as a One ASP.NET Web Application project!