Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Existing C++ Source Code into Visual Studio

Tags:

I am trying to import an existing c++ application's source into visual studio to take advantage of some specific MS tools. However, after searching online and playing with visual studio, I cannot seem to find an easy way to import existing c++ source code into visual studio and keep it structurally intact.

The import capacity I did find flattens out the directories and puts them all into one project. Am I missing something?

(This is all unmanaged C++, and contains specific builds for win/unix)

like image 976
pinvoke Avatar asked Jan 31 '11 16:01

pinvoke


2 Answers

With no project/solution loaded, in Visual Studio 2005 I see this menu item:

File > New Project From Existing Code...

After following the wizard, my problem is solved!

Switching the "Show All Files" button shows the complete hierarchy with all directories and files within.

If the New Project From Existing Code... option isn't available, you'll need to add it in Tools > Customize...

Tools > Customize...  Commands tab, File menu, Add Command button, File menu, New Project From Existing Code...

like image 159
Zac Avatar answered Oct 11 '22 19:10

Zac


I am not aware of any general solution under the constraints given - specifically having to create many projects from a source tree.

The best option I see is actually creating the project files by some script.

  • Creating a single project manually (create empty project, then add the files),
  • Configure it as close as possible as desired (i.e. with precompiled headers, build configurations, etc.)
  • Use the .vcproj created as skeleton for the project files to be created

A very simple method would file list, project name etc. with "strange tokens", and fill them in with your generator. If you want to be the good guy, you can of course use some XML handling library.


Our experience: We actually don't store the .vcproj and .sln in the repository (git) anymore, but a python script that re-genrates them from the source tree, together with VS 2008 "property sheet templates" (or whatever they are called). This helps a lot making general adjustments.

The project generation script contains information about all the projects specialties (e.g. do they use MFC/ATL, will it create DLL or an EXE, files to exclude).

In addition, this script also contains dependencies, which feeds the actual build script.

This works quite well, the problems are minor: python requried in build systems, not forgetting to re-gen the project files, me having to learn some python to make adjustments to some projects.


@Michael Burr "How complex are the python scripts and whatever supporting 'templates' you might need?"

I honestly can't tell, since I gave the task to another dev (who picked python). The original task was to provide a build script, as the VS2008 solution build was not good enough for our needs, and the old batch file didn't support parallelization. .vcproj generation was added later. As I understand his script generates the .vcproj and .sln files from scratch, but pulls in all the settings from separate property sheets.

Pros:

  • Adding new configurations on the fly. Some of the projects already had six configurations, and planning for unicode support meant considering doubling them for a while. Some awkward tools still build as MBCS, so some libs do have 8 configs now. Configuring that from hand is a pain, now it just doesn't bother me anymore.

  • Global changes, e.g. moving around relative project paths, the folder for temp files and for final binaries until we found a solution we were happy with

  • Build Stability. Merging VC6 project files was a notable source of errors for various reasons, and VC9 project files didn't look better. Now things seem isolated better: compile/link settings in the property sheets, file handling in the script. Also, the script mostly lists variations from our default, ending up easier to read than a project file.

Generally: I don't see a big benefit when your projects are already set up, they are rather stable, and you don't have real issues. However, when moving into the unknown (for us: mostly VC6 -> VC9 and Unicode builds), the flexibility reduced the risk of experiments greatly.

like image 38
peterchen Avatar answered Oct 11 '22 17:10

peterchen