Convert Web-site to Web Application.

M

mark4asp

Some notes to jog my memory in case I have to do this evil time-wasting
thing again.

This was using VS2008 with Asp.Net 3.5 websites.

Why.

You need to do this as a first step to make parts of the web project
testable.

Steps

1. Ensure that the website uses just two namespaces
(this worked for me!).

I put all web pages in one namespace and all App_Code stuff
in a 2nd namespace. I also moved all the code in App_Code to
the root of App_Code.

2. Ensure that every bit of code is in a namespace.

[NotePad++ is excellent for adding and modifying stuff like this
because it has search and replace supporting both regular expressions
and 'replace in files']

3. Build and check that it works [The website after these edits].

4. Create a new Web App Project.

5. Delete web.config and Default.aspx

6. Add any binaries to /Bin

7. Add any references used by the website

8. Build the project!

9. Copy relevant files over from the website to the web app. [Do not
over-write the /properties, /bin, etc.]. Any web references (e.g. to
external web services) will need to be recreated.

10. From solution explorer, with the root of the project selected,
apply the command Convert to web application.

11. When it fails!, identify the problem and remove it by fixing the
problem in the website [compiling and testing the website make sure it
works]. The most likely cause of failure is a broken server control.
This will need to be rewritten first or entirely removed (and added
back later).

12. IMPORTANT. If the conversion got as far are renaming /App_Code as
/Old_App_Code then one can proceed otherwise stop, delete the entire
web application project and start again! - it's pointless continuing
otherwise because you will just waste your time attempting to
understand meaningless compiler error messages. If the App_Code can't
be seen despite using clauses referencing it then the entire project is
junk and should be ditched.

I had to attempt the conversion 4 times before it finally worked - each
time collecting a new clue regarding what was wrong and fixing the
problem in the website before continuing with the next attempt.

By next attempt I mean deleting the entire failed web application and
starting from scratch.

13. The final part just involves fixing a few pages which failed to
convert because they were using a dodgy control. After removing the
control from the page, click on the page and apply "Convert to web
application" to that page. Do this for every broken page or
UserControl. The control will need to be fixed and added later. Add it
to your to do list.

14. A few namespace changes may be needed here but before continuing
ensure that it now builds and works.

15. Global.aspx and web services may be tricky.

15. All the App_Code can now be moved to a new project in the same
solution. Each page will then need a reference to the new project (as
will the web application itself).

16. Procede stepwise, removing code to new projects, adding references
and namespaces. I had to create a new web service project, data
project, model project (containing no depencies at all) and finally a
business project. Moving relevant code from /Old_App_Code to them,
adding references and using clauses as they were created, building the
solution after adding each new project. NotePad++ comes in really handy
here for the namespace changes.

17. Now I just need to fix the broken server control and add it back to
the pages I deleted if from then it will be fine and dandy again - and
testable at last. Oh and I just need to write the tests.

This was such a pain for me to do and I wasted so much time trying to
proceed manually after failure to (a) sort out namespaces beforehand
and (b) attempting to manually fix it after the conversion wizard gave
up before the /Old_App_Code folder was created. Remember to give up at
this point and try the conversion from the beginning again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top