Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / MFC

Multiple Projects in One Solution

1.00/5 (2 votes)
22 Apr 2013GPL32 min read 43.8K  
Multiple Projects in One Solution

Image 1

Programming Tip for Visual Studio

When creating multiple executables that are closely related, it can be very beneficial to have several projects within one solution.

Background

I needed this when writing my Server and Client TCP applications. The Server was to be run on one computer while the Client runs on another. However, they are so inter-dependent on each other it was helpful to have both in the same solution. I was unable to find clear instructions so I wrote this tip. Here is a link to the article and project that prompted this need: My TCP/IP Article

Using the Tip

Start the project to create a solution and a project in the usual manner, but stop with the New Project dialog displayed. I have used C++ with MFC but I suspect this will work for all languages.

Normally at this stage, I fill in the [Project]Name and the solution name is automatically filled in. Then I click OK and go on. This time, after entering the [Project]Name, enter a solution name. For this example, the [Project]Name is First_Project and the solution name is Two_Project_Solution.

two_solution_dialog

Ok that and complete any selections you may need. The solution explorer should look something like this.

solution_explorer_1

That should all be familiar. In the above image I have jumped ahead a bit and selected the solution rather than the project just to highlight it.

The next step is to create the second project. Right click on the solution and select Add then New Project. The dialog field Location defaults to the location of the current project so just leave that field alone. Go through the same steps as for the first project and click the final OK.

My example named the second project Second_Project.

In the below image I have closed (un-expanded) the two projects so just the project names are shown.

solution_explorer_2

When writing your code, nothing changes. Select the solution and go to work.

The next change is for running your solution. Right click on the Solution and select Set Startup Projects. Here is the dialog.

select_startup.jpb

The default for me was Single startup project. In the image I have changed it to Multiple startup projects and opened the drop down box for the first project to show the options. When working my TCP/IP code, I would set one to Start and the other to Start without debugging. Start obviously implies Start with debugging.

That is it. Happy coding.

History

Original post: 22 April 2013  

23 April 2013, first image was incorrect, edited title.  

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)