C#: How to convert a Website project to a Web Project

前端 未结 2 627
迷失自我
迷失自我 2021-01-01 00:49

UPDATE: All of these problems was for converting a Website application to a Web Project in Visual Studio. Once I dug in and I found the solution, as I marked as answer belo

相关标签:
2条回答
  • 2021-01-01 01:14

    Fyi, I found the solution. It's easier than you think.

    You simply right-click your new Web Project and there is an option for "Convert to Web Application." This does some interesting things. First, it creates the [file].aspx.designer.cs auto-generated file. This got rid of 99% of my errors, as it was because the codebehind could not find a reference to the control (see screenshot in my question above).

    This also re-writes the <%@ Page %> decleration in your aspx file to to inherit from the code behind's new name/namespace.

    All that was left was some assembly reference issues and done!

    The How To is:

    1) Create a new Web Project, copy all files from your old Website project to the new Web Project.

    2) Fix all references to your assemblies you KNOW you will need.

    3) Right-click on the Web Application and select Convert to Web Application. Closely inspect the error and warning log. Re-convert at will once you fix things.

    If any aspx or ascx files do not have a designer.cs file, then the conversion failed on that file. Fix the references, namespace, etc and re-convert.

    Tip #1: Make sure you have all references added before you Convert to Web Application. Sometimes a number of errors can happen.

    Tip #2: Even though it looks like it completed, look for errors after the convert. It will point you to files it was unable to convert, so you need to work on them.

    Tip #3: You can re-convert any sub-directory, or any file, any number of times. Say you had multiple errors in #2 you were working to fix, you can re-convert that file or directory multiple times until you fix it. Re-converting does not hurt the existing application.

    0 讨论(0)
  • 2021-01-01 01:18

    I can't think of a solution other than writing a little console app that would go through all of the files and modify them for you.

    0 讨论(0)
提交回复
热议问题