0

Visual Studio seems to consist of a single solution file (*.sln) along with one or more project files (a C# project would have the *.csproj extension).

I have been playing around with a console application that parses existing directory entries to create solution files with the associated project files.

It works, but every time I run into a new project here at work I find myself spending a week or more debugging my console project so that it can churn out a solution for that particular work project.

Is there something out there already that can create a VS solution out of an existing file structure?

As you can tell from my screen capture below, these projects are nested very deep, so it would take a very long time to do this with the apps folder below with the "by mouse" technique in the Visual Studio IDE.

screen capture

  • Have you thought about writing a custom App wizard? – rrirower Feb 05 '14 at 15:43
  • I'm not sure if I understand. I think the VS Console Application that I've been spending a few weeks on is a Custom App Wizard. Did you mean something else? –  Feb 05 '14 at 15:50
  • Possibly. Visual Studio exposes its internal project creation framework via its [DTE object model](http://msdn.microsoft.com/en-us/library/96xz4cw2(v=vs.100).aspx). In effect you create the template files for the solution and it appears in the New Project dialog box. Is that what you've been using? – rrirower Feb 05 '14 at 16:00
  • Sort of. I've been loading Solution and Project files into Notepad to see how they are structured, and recreating that by writing that data using a TextWriter. I am re-inventing the wheel. –  Feb 05 '14 at 17:41
  • 1
    If you've got the time, I would invest in using the DTE framework. I've created a custom wizard and it's very easy to extend the templates when you need it to grow. – rrirower Feb 05 '14 at 18:30
  • 1
    I wrote a tool for this a couple of years ago; you can find it in my Boost-licensed CxxReflect library: http://cxxreflect.codeplex.com/SourceControl/latest#utility/create_sln_from_filesystem/main.cpp – James McNellis Mar 26 '14 at 21:14

2 Answers2

0

I created the custom console application that is posted in this post:

https://stackoverflow.com/a/22153536/153923

I invite others to contribute how they approached this solution, though.

Community
  • 1
  • 1
0

So, I found out today that this feature already exists in Visual Studio.

Link 1: How to: Create a Project from Existing Code Files

Link 2: How to: Create a Project from Existing Code Files

Basically, though, it says this (just in case the MSDN links get changed or deleted):

You can create a Visual Studio project from an existing app—for example, an app that you obtained from an online source. Project and solution files are created on your computer and the other relevant files are added. A project can be created from Visual C++, Visual Basic, or Visual C# code files.

Security note Security Note We recommend that you determine the trustworthiness of existing code files before you import them into Visual Studio, because Visual Studio will execute some of the code in a fully trusted process when you open the newly created project.

To create a project from existing code files

  1. On the menu bar, choose File, New, Project From Existing Code.

The Create New Project from Existing Code Files wizard opens.

  1. Use the wizard to specify the details of the existing code files that will be added to the project and the application that will be created when you build the project.

Another good answer was given by cbp in Visual Studio: Create a web application from existing code:

--

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.

Great idea!

Community
  • 1
  • 1