Thursday, November 14, 2013

Migrating ASP.NET Web Forms to One ASP.NET

 

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:

 

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>
</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{1D046BDD-BA8E-4C93-9CB4-A8886AB98E78}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OneASPNet</RootNamespace>
<AssemblyName>OneASPNet</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<UseIISExpress>true</UseIISExpress>
<IISExpressSSLPort />
<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />
<IISExpressUseClassicPipelineMode />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Core" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web.Services" />
<Reference Include="System.EnterpriseServices" />
<Reference Include="System.Web.DynamicData" />
<Reference Include="System.Web.Entity" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="AspNet.ScriptManager.bootstrap">
<HintPath>..\packages\AspNet.ScriptManager.bootstrap.3.0.0\lib\net45\AspNet.ScriptManager.bootstrap.dll</HintPath>
</Reference>
<Reference Include="AspNet.ScriptManager.jQuery">
<HintPath>..\packages\AspNet.ScriptManager.jQuery.1.10.2\lib\net45\AspNet.ScriptManager.jQuery.dll</HintPath>
</Reference>
<Reference Include="Microsoft.ScriptManager.MSAjax">
<HintPath>..\packages\Microsoft.AspNet.ScriptManager.MSAjax.5.0.0\lib\net45\Microsoft.ScriptManager.MSAjax.dll</HintPath>
</Reference>
<Reference Include="Microsoft.ScriptManager.WebForms">
<HintPath>..\packages\Microsoft.AspNet.ScriptManager.WebForms.5.0.0\lib\net45\Microsoft.ScriptManager.WebForms.dll</HintPath>
</Reference>
<Reference Include="System.Web.Optimization, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<HintPath>..\packages\Microsoft.AspNet.Web.Optimization.1.1.1\lib\net40\System.Web.Optimization.dll</HintPath>
</Reference>
<Reference Include="WebGrease">
<Private>True</Private>
<HintPath>..\packages\WebGrease.1.5.2\lib\WebGrease.dll</HintPath>
</Reference>
<Reference Include="Antlr3.Runtime">
<Private>True</Private>
<HintPath>..\packages\Antlr.3.4.1.9004\lib\Antlr3.Runtime.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<Private>True</Private>
<HintPath>..\packages\Newtonsoft.Json.5.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.Web.Optimization.WebForms">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.Web.Optimization.WebForms.1.1.1\lib\net45\Microsoft.AspNet.Web.Optimization.WebForms.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.FriendlyUrls">
<HintPath>..\packages\Microsoft.AspNet.FriendlyUrls.Core.1.0.2\lib\net45\Microsoft.AspNet.FriendlyUrls.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Reference Include="System.Web.Razor">
<HintPath>..\packages\Microsoft.AspNet.Razor.3.0.0\lib\net45\System.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Web.Webpages">
<HintPath>..\packages\Microsoft.AspNet.Webpages.3.0.0\lib\net45\System.Web.Webpages.dll</HintPath>
</Reference>
<Reference Include="System.Web.Webpages.Deployment">
<HintPath>..\packages\Microsoft.AspNet.Webpages.3.0.0\lib\net45\System.Web.Webpages.Deployment.dll</HintPath>
</Reference>
<Reference Include="System.Web.Webpages.Razor">
<HintPath>..\packages\Microsoft.AspNet.Webpages.3.0.0\lib\net45\System.Web.Webpages.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Web.Helpers">
<HintPath>..\packages\Microsoft.AspNet.Webpages.3.0.0\lib\net45\System.Web.Helpers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Mvc">
<HintPath>..\packages\Microsoft.AspNet.Mvc.5.0.0\lib\net45\System.Web.Mvc.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Content Include="About.aspx" />
<Content Include="Contact.aspx" />
<Content Include="Content\bootstrap.css" />
<Content Include="Content\bootstrap.min.css" />
<Content Include="Content\Site.css" />
<Content Include="fonts\glyphicons-halflings-regular.svg" />
<Content Include="packages.config" />
<Content Include="fonts\glyphicons-halflings-regular.woff" />
<Content Include="fonts\glyphicons-halflings-regular.ttf" />
<Content Include="fonts\glyphicons-halflings-regular.eot" />
<None Include="Scripts\jquery-1.10.2.intellisense.js" />
<Content Include="Scripts\bootstrap.js" />
<Content Include="Scripts\bootstrap.min.js" />
<Content Include="Scripts\jquery-1.10.2.js" />
<Content Include="Scripts\jquery-1.10.2.min.js" />
<Content Include="Scripts\modernizr-2.6.2.js" />
<Content Include="Scripts\respond.js" />
<Content Include="Scripts\respond.min.js" />
<Content Include="Scripts\WebForms\DetailsView.js" />
<Content Include="Scripts\WebForms\Focus.js" />
<Content Include="Scripts\WebForms\GridView.js" />
<Content Include="Scripts\WebForms\Menu.js" />
<Content Include="Scripts\WebForms\MenuStandards.js" />
<Content Include="Scripts\WebForms\MSAjax\MicrosoftAjax.js" />
<Content Include="Scripts\WebForms\MSAjax\MicrosoftAjaxApplicationServices.js" />
<Content Include="Scripts\WebForms\MSAjax\MicrosoftAjaxComponentModel.js" />
<Content Include="Scripts\WebForms\MSAjax\MicrosoftAjaxCore.js" />
<Content Include="Scripts\WebForms\MSAjax\MicrosoftAjaxGlobalization.js" />
<Content Include="Scripts\WebForms\MSAjax\MicrosoftAjaxHistory.js" />
<Content Include="Scripts\WebForms\MSAjax\MicrosoftAjaxNetwork.js" />
<Content Include="Scripts\WebForms\MSAjax\MicrosoftAjaxSerialization.js" />
<Content Include="Scripts\WebForms\MSAjax\MicrosoftAjaxTimer.js" />
<Content Include="Scripts\WebForms\MSAjax\MicrosoftAjaxWebForms.js" />
<Content Include="Scripts\WebForms\MSAjax\MicrosoftAjaxWebServices.js" />
<Content Include="Scripts\WebForms\SmartNav.js" />
<Content Include="Scripts\WebForms\TreeView.js" />
<Content Include="Scripts\WebForms\WebForms.js" />
<Content Include="Scripts\WebForms\WebParts.js" />
<Content Include="Scripts\WebForms\WebUIValidation.js" />
<Content Include="Scripts\_references.js" />
<Content Include="Default.aspx" />
<Content Include="favicon.ico" />
<Content Include="Global.asax" />
<Content Include="Site.Master" />
<Content Include="ViewSwitcher.ascx" />
<Content Include="Web.config" />
<Content Include="Bundle.config" />
<None Include="Project_Readme.html" />
<Content Include="Scripts\jquery-1.10.2.min.map" />
<Content Include="Site.Mobile.Master" />
<Content Include="Views\web.config" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
<None Include="Web.Release.config">
<DependentUpon>Web.config</DependentUpon>
</None>
</ItemGroup>
<ItemGroup>
<Compile Include="App_Start\BundleConfig.cs" />
<Compile Include="About.aspx.cs">
<DependentUpon>About.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="About.aspx.designer.cs">
<DependentUpon>About.aspx</DependentUpon>
</Compile>
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="Contact.aspx.cs">
<DependentUpon>Contact.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Contact.aspx.designer.cs">
<DependentUpon>Contact.aspx</DependentUpon>
</Compile>
<Compile Include="Default.aspx.cs">
<DependentUpon>Default.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Default.aspx.designer.cs">
<DependentUpon>Default.aspx</DependentUpon>
</Compile>
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Site.Master.cs">
<DependentUpon>Site.Master</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Site.Master.designer.cs">
<DependentUpon>Site.Master</DependentUpon>
</Compile>
<Compile Include="Site.Mobile.Master.cs">
<DependentUpon>Site.Mobile.Master</DependentUpon>
</Compile>
<Compile Include="Site.Mobile.Master.designer.cs">
<DependentUpon>Site.Mobile.Master</DependentUpon>
</Compile>
<Compile Include="ViewSwitcher.ascx.cs">
<DependentUpon>ViewSwitcher.ascx</DependentUpon>
</Compile>
<Compile Include="ViewSwitcher.ascx.designer.cs">
<DependentUpon>ViewSwitcher.ascx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
<Folder Include="Controllers\" />
<Folder Include="Models\" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
<ProjectExtensions>
<VisualStudio>
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
<WebProjectProperties>
<UseIIS>True</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>12412</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:12412/</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>
</VisualStudio>
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>


Now, for the dissection of the project:


First of all, you will need to make sure that you copy over the appropriate ProjectTypeGuids elements:


<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>


The remainder of the editing work involves reviewing the individual ItemGroups for content to copy over:



  1. You will need to copy over any ItemGroup elements that covers any required References
  2. You will need to copy over any ItemGroup elements that create the App_Start, Views, Content, Controllers and Models directories. 
  3. 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!

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. How confident you are with "One Asp.Net" feature for a complex asp.net project?

    ReplyDelete