VS: Convert WebForms WebSite to WebApp

Converting a Visual Studio Web Site to a Web Application makes it easier to have control of all the references.

Here are steps todo for that procedure

  1. Create an empty ASP.NET application with WebForms selected
  2. Drag’n’drop files from the old website project into your new webapp project (except for web.config)
  3. On the imported .cs files change Build Action from Content to Compile
  4. Close Visual Studio
  5. For each <MyPage>.aspx.cs, <MyMaster>.master.cs and <MyControl>.ascx.cs file:
    1. Edit the .cs file – change CodeFile=… to CodeBehind=…
    2. Create an empty file called <MyPage>.aspx.designer.cs
    3. In the .csproj file paste link to the new file just below the include of the MyPage.aspx:
    4. <Compile Include=”MyPage.aspx.designer.cs”>
      <DependentUpon>MyPage.aspx</DependentUpon>
      </Compile>
    5. Open Visual Studio
    6. Dran’n’drop a Label control from the Toolbox to the end of your markup
    7. Open the designer.cs file – now all (or most) the controls should be auto-generated in there
    8. Delete the label you just added from the markup
    9. You might have non-asp webcontrols like normal html controls where you would need to add the control in the non-designer file e.g.
      protected global::System.Web.UI.HtmlControls.HtmlAnchor lnkAbout;
      for a markup a hyperlink “<a href=…”
    10. If in doubt or lost: Create a new page or control – paste content and rename it.
  6. Paste content from the website web.config into the webapp web.config
  7. Add missing references
  8. Compile and run

https://social.msdn.microsoft.com/Forums/en-US/128202d7-5ecb-4921-8ac3-e173d4824235/forcing-regeneration-of-the-designercs-file?forum=csharpide

The End

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: