Sti
Sti

Reputation: 8484

How can I run/debug a given project based on the solution configuration?

I have multiple projects in a Solution. The main two "runnable" projects are Server and Client. The dropdown next to the "Run/Debug"-button shows "Debug" and "Release". This seems to be "Solution Configurations" managing several "Project Configurations". I am looking for a way to replace these with "Solution Configurations" for "Debug Client", "Release Client", "Debug Server" and "Release Server". With this, I was hoping that simply selecting any of the configurations and hitting play would build the correct "Project Configurations" AND run/debug the expected project. However, I can't find any setting to decide which project is actually started. Only "build"/"deploy". I still have to manually select which project to "set as startup project".

I can see in the solution properties that I can set multiple startup projects. This "property"-page would've been absolutely perfect if I was able to change the "Configuration" in the top left, however the entire config/platform-area is grayed out with "N/A". I can only change it at a general level, and if I change both Client and Server to "Start", then they both always start, which is definitely not what I want. I just want one to start, based on which solution configuration I've chosen. Is this not possible?

Upvotes: 2

Views: 98

Answers (1)

Timothy G.
Timothy G.

Reputation: 9045

I found an extension called SwitchStartupProject that can achieve what you are after. Using this extension, you can configure a solution startup file that is written in JSON. As an example, I wrote mine like so:

{
  /*  Configuration File Version  */
  "Version": 3,

  /*  Create an item in the dropdown list for each project in the solution?  */
  "ListAllProjects": false,
  "MultiProjectConfigurations": {
    "ProjectA": { /*  Configuration name (appears in the dropdown)  */
      "Projects": {
        "ProjectA": {} /*  Starting ProjectA  */
      },
      "SolutionConfiguration": "ProjectAConfig", /*  Activating solution configuration "ProjectAConfig"  */
      "SolutionPlatform": "Any CPU" /*  and solution platform "Any CPU"  */
    },
    "ProjectB": { /*  Configuration name (appears in the dropdown)  */
      "Projects": {
        "ProjectB": {} /*  Starting ProjectB  */
      },
      "SolutionConfiguration": "ProjectBConfig", /*  Activating solution configuration "ProjectBConfig"  */
      "SolutionPlatform": "x86" /*  and solution platform "x86"  */
    },
    "netcoreapi": { /*  Configuration name (appears in the dropdown)  */
      "Projects": {
        "netcoreapi": {} /*  Starting netcoreapi*/
      },
      "SolutionConfiguration": "Debug", /*  Activating solution configuration "Debug"  */
      "SolutionPlatform": "Any CPU" /*  and solution platform "Any CPU"  */
    }

  }
}

Result of this:

Startup switching

Instead of changing the configuration you want, you select which project you want to start, and in turn this can change the configuration used. You can even change the platform as well as demonstrated, among other things. Check out the configuration page of the extension to learn some more.

Upvotes: 2

Related Questions