24

I have an existing directory structure that is all nicely checked into SVN, so I don't really want to mess with it.

The website code lives in a folder called C:\Projects\TheProject\Website. I want to bring the website files into a new Web Application Project without changing the directory structure.

Ideally the resulting file structure would look like this:

  • C:\Projects\TheProject\TheProject.sln
  • C:\Projects\TheProjects\Website\Website.csproj

No matter what I try I dont get what I want. There is no option to create a web application from existing code. This is very frustrating. Does anyone know if it is possible?

cbp
  • 25,252
  • 29
  • 125
  • 205

7 Answers7

34

OK I figured it out. It's weird, but the following steps will work:

  1. Open fresh copy of Visual Studio
  2. File->New Project, select Web Application
  3. Use the following settings:

    Name: Website (this is the name of the existing folder with the website files in it) Location: C:\Temp\ (anywhere will do for now) Solution Name: TheProject (name of the existing project's root folder) Check "Create directory for solution"

  4. Delete the auto-created Default, Global and Web.config files

  5. Save All and close Visual Studio
  6. In Windows Explorer, copy the new folder on top of the existing folder so that the files are merged.

  7. Double click on the sln file to open Visual Studio again.

  8. Select "Show all files" (at the top of Solution Explorer)

  9. Right click on any files or folders you want to add and select Include in Project.

cbp
  • 25,252
  • 29
  • 125
  • 205
  • I like this answer better. The accepted answer doesn't really work as well with SVN. –  Nov 25 '14 at 20:53
  • For me this added everything as a content file, which isn't useful for things like .aspx and .vb files. – Pedro May 04 '16 at 21:00
  • Downvoted because AJ.'s answer below works better and is cleaner – wvdz May 15 '17 at 15:00
30

Have you tried something like this?

  1. Create a new Visual Studio Blank Solution from File-->New Project-->Other Project Types-->Blank Solution, making sure to specify c:\Projects\TheProject as your solution directory.
  2. Copy the folder with all of the existing website stuff into c:\Projects\TheProject\WebSite.
  3. Back in Visual Studio, right-click your solution in Solution Explorer and select "Add Existing Website." Then, pick your c:\Projects\TheProject\WebSite folder.

Good luck, HTH.

AJ.
  • 16,368
  • 20
  • 95
  • 150
  • 3
    If you want 3 steps instead of 9, upvote this answer ;) No need to create a bloated asp.net-templated project first. – Nilzor May 05 '14 at 07:49
  • Only tried this solution, and it works against the codes I have downloaded from codeproject. Thanks – Rajesh Thampi Aug 16 '17 at 07:29
  • I have did the same, but was unable to build the solution. It shows almost 70 errors for each control and complains that it does not exist in the context. – Jamshaid K. Sep 27 '17 at 10:30
  • 2
    This doesn't answer the question, because it doesn't create a Web Application Project, it only adds the existing code to the solution as a plain website without a project, which does not function in the same way. – Daniel Hume Jun 05 '19 at 14:47
13

Create a new web project with a .csproj file. Delete all the files it comes with. Drag everything into the project.

tsilb
  • 7,977
  • 13
  • 71
  • 98
1

In the File menu, click Open, and then click Web Site. Choose the root folder where your Web Site is located

0

On top of @cbp answer I would like to add that if you would like to keep the Version control history of those files - in step 6 - instead of copy do:

git mv original-website/* new-web-application-directory/.
chenop
  • 4,743
  • 4
  • 41
  • 65
-1

What have you tried? I normally create a blank solution and add existing folders (drag and drop on solution explorer works best), and have not had a problem.

RiddlerDev
  • 7,370
  • 5
  • 46
  • 62
-4

in VS 2008 File->New->Project From Existing Code

Funky Dude
  • 3,867
  • 2
  • 23
  • 33