Search code examples
.netdockervisual-studio-2022docker-swarmvisual-studio-debugging

How do you debug 2 seperate Visual Studio solutions at once in Docker?


I do you set up 2 separate Dotnet solutions in Visual Studio 2022 that can debug at the same time and interact, with docker? THIS SOUNDS SO SIMPLE, WHERE ARE THE DOCS???

Most of the documentation and example I have seen involve both apps' projects being in the same solution, and maybe using a docker compose file. Problem is, I can't elect to combine these repositories, and it doesn't make sense to manage git bundling things into one solution. Idk if that would change my outcomes.

Attempting to set up a couple typical Dockerfiles beginning from Add/ Docker Support... results in, what I assume is, one application blocking the other because they are set to the same port(s). I can run either of them if it's the first one to be executed, but then the second fails with a last second build error from launchSettings.json:

CTC1011 The Docker container could not be started, because the following port(s) are already in use: 5000, 5001`

Substituting one app's ports with 8080, 8081 results getting a little further in the launch process, but a windows popup explains: One or more errors occurred. In the logs I can see it was trying to connect to https://localhost:5001/swagger, and since the other window has opened to https://localhost:8081/swagger, I would assume it would be okay, but instead there are "unable to attache to browser" errors in the logs.

example launchSettings.json` related snippets:

"AppName": { // In either file AppName = "App1" or "App2"
  "applicationUrl": "https://localhost:5001;http://localhost:5000",
  // Or on App2: "applicationUrl": "https://localhost:8081;http://localhost:8080",
"Docker": {
  "commandName": "Docker",
  "launchBrowser": true,
  "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Dev"
  },
  "sslPort": 5001, // Or on App2 8081
  "httpPort": 5000, // Or on App2 8080

I picked 8080, 8081 because I have seen those ports in use debugging front end apps, and I am fairly certain these 2 dotnet solutions would not reference them.

example Dockerfile` related snippets:

EXPOSE 80 // Also tried App2 = 81
EXPOSE 443 // Also tried App2 = 444

I have the debuggers set to Docker launch profiles, I have thoroughly searched for redundant port number appearance.

One peculiar thing I see in the Docker ui's Container screen is, App2 will have 4 ports:

8081:443,
55010:444,
8080:80,
55011:81

55010 and 55011 does not appear anywhere in either solutions' code.

App 1 will show a more expected report:

5001:443,
5000:80

It does not matter what order I debug these in, the Docker container ports are always rebuilt as seen above.

Any help would be greatly appreciated... Next, I'm going to have to point one of these apps at each other... so bonus points for tips on that!


Solution

  • Deleting C:\Users\{Username}\AppData\Local\Microsoft\VisualStudio\{VisualStudioVersion}\privateregistry.bin resolved the issue 🤦. VS22 gets it's ports gummed up if you're the type that debugs a lot of different apps.