As I dig deeper into the capabilities of Visual Studio, I have seen that you can have multiple projects in a single solution. I must be missing something because I can't come up with a reason to ever do this? My guess is that I don't understand the benefit. So, I thought I would pose the question to my fellow developers and ask for some real world situations where you had multiple projects in one solution, the benefit obtained, and at a high level, what each project did and why they needed linked into one solution. Also, were they all exes, dlls, etc.?

Thanks in advance for your input.

codeorder commented: interesting topic :) +1

Dani AI

Generated

the big win is separation of responsibilities. One solution can hold your UI, domain logic, data access, tests, and tools as discrete projects so you can reuse code, compile faster, and ship only what each target needs. Building on ’s point, a typical setup might be:

  • MyApp.Core (class library, all business logic and models)
  • MyApp.Desktop or MyApp.Web (the executable that references Core)
  • MyApp.Tests (unit tests that reference Core)
  • MyApp.Tools (console importer, seeding scripts, etc.)

Executable projects (EXE) consume libraries (DLL). Keep the reusable parts in DLLs and reference them from each app. You can wire projects together either in the .csproj file or with the CLI:

<ItemGroup>
  <ProjectReference Include="..\MyApp.Core\MyApp.Core.csproj" />
</ItemGroup>
dotnet add .\MyApp.Desktop\MyApp.Desktop.csproj reference ..\MyApp.Core\MyApp.Core.csproj

This keeps logic testable and shareable across a desktop app, a web API, and any background jobs you add later. Class library projects are designed exactly for this use. (learn.microsoft.com)

On your follow-up about which EXE runs: right-click the project you want and choose Set as Startup Project. For multiple processes (e.g., ’s admin and client) you can start both when you press F5: right-click the solution > Properties > Common Properties > Startup Project > Multiple startup projects, then set each to Start. (github.com)

If you are on recent Visual Studio, you can even save and share these multi-launch settings as a launch profile (.slnLaunch) so everyone on the team gets the same behavior without reconfiguring their IDE. Enable Multi-Project Launch Profiles (VS 2022 17.11+), create a profile, and check the Share option so it lives in source control. (devblogs.microsoft.com)

Recommended Answers

All 5 Replies

Have a look at MSDN article - Solution (.Sln) File

This tells me how and some benefits, which went right over my head right now, probably because I'm still missing the why. Everything I have built has been one solution / one project. Why would you have multiple projects in one solution and what would be in each of them. Please give details such as the solution was to do xxx, project 1 did yyy and project 2 did zzz.

>I must be missing something because I can't come up with a reason to ever do this?

What we need is a pragmatic approach. Have a look at some good open source projects at http://www.codeplex.com/

>where you had multiple projects in one solution, the benefit obtained, and at a high level

It is nearly impossible for me to put all kind of programming work in a single project. For example, I've windows-app (database) project. My project includes - database schema and object design, model classes, some custom controls, and of course testing(unit-test). All these activities need a separate project definition. So, database and model classes are developed in database project and library project respectively and code will tested in unit-test projects. User-Interface (custom controls) project contains custom control classes which I want to use them on windows-app.

After few days I've been told that they (my client) are also interested in web-app and without any hesitation I've said OK! (I've added another web-project in my current solution).


For more information on Solution or Project Container read following articles:

1. Introduction to Solutions, Projects, and Items
2. Solutions as Containers (Advantages)

I wanted to post a follow up now that I finally got to have a conversation with someone that does this for a living.

Many of his projects in a solution create DLLs that are used used by the EXE. He also explained that if the solution has multiple projects that generate EXEs, even though pressing the F5 to debug will only run the primary EXE, when the solution is published, it will generate multiple EXEs. There is also a way to switch which EXE is primary for debugging purposes but I need to do additional research to find out where to change it.

I hope this additional information helps the next person trying to figure this out.

think of a internet cafe as one solution, the admin program (for you) is one project and the client (for customer) is another project

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.