Skip to content

Better VisualStudioCredential compose support for multiple services #467

Open

Description

@AHarman

Hi, I have a situation where I want to run two services locally as one is dependent on the other. They are stored in different repositories. Both, when running locally, rely on VisualStudioCredential. myProject is in the repo I'm putting the compose files in and it depends on upstreamApi, which is defined in a different repository.

I have a docker-compose.yml like this:

services:
  myProject:
    image: myProject
    environment:
      ...
    build:
      context: ..
      dockerfile: src/MyProject/Dockerfile
    ports:
      - "5255:8080"

then the docker-compose.override.yml:

services:
  myProject:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
      - ASPNETCORE_HTTP_PORTS=8080
    ports:
      - "5255:8080"
    volumes:
      - ${APPDATA}/Microsoft/UserSecrets:/home/app/.microsoft/usersecrets:ro
      - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro

And a second compose like this to extend the first one, overriding the configured URL for the upstream API and getting that API to run in docker compose. This one is called docker-compose.fullstack.yml and is added via the AdditionalComposeFilePaths property in the dcproj file.

services:
  myProject:
    environment:
      upstreamApi__BaseUrl: http://upstreamApi:8080

  upstreamApi:
    image: myrepo/azurecr.io/upstream-api:latest
    environment:
      ASPNETCORE_ENVIRONMENT: Staging
      ASPNETCORE_HTTP_PORTS: 8080
    ports:
      - "5260:8080"
    volumes:
      - ${APPDATA}/Microsoft/UserSecrets:/home/app/.microsoft/usersecrets:ro
      - ${APPDATA}/Microsoft/UserSecrets:/root/.microsoft/usersecrets:ro
      - C:\Program Files\Microsoft Visual Studio\18\Professional\MSBuild\Sdks\Microsoft.Docker.Sdk\tools\linux-x64\net6.0:/VSTools:ro

I've run into a few problems here, but the big one is getting the Visual Studio authentication to work. I've attempted to copy some of the properties from the generated compose file into my own to try to do this, one of which you can see right at the end there. There are docs here but they are a bit sparse on actual detail. The docs point to the Azure Identity README but that doesn't really explain it either.

Is there any way I can provide the visual studio credential proxy to multiple services? Or is there a better way that I'm missing here?

Activity

  1. changed the title [-]Better compose support for multiple services[/-] [+]Better VisualStudioCredential compose support for multiple services[/+] on Oct 29, 2026
  2. NCarlsonMSFT commented on Oct 29, 2026

    @NCarlsonMSFT
    Member

    As of now our support for the VisualStudioCredential in containers is limited to the containers started for local debugging. So, an arbitrary image (even if you know you own it) has no way of activating that. You're mapping the tools, but VS won't run them b/c that container isn't "ours"

    Luckily supporting unexpected configurations is a fun hobby of mine.

    The few options that spring to mind:
    Best supported:
    If you have access to the repo for upstreamApi you could clone it as a sub module, allowing you to add that project to your solution, and the compose project. At that point it should work like any other project.

    A slight variant on this:
    You could take the above a step further and have a meta repo that includes your two existing repos as sub-modules and then containers the special solution / compose project for coordinating debugging them together. This may make sense if the two can be worked on and debugged independently (such as using a mock of upstreamApi) but you want a convenient way to work on them in a combined way while maintaining separation of the repos in general.
    // This would be my preference in your situation (unless I am missing key context)

    Not really supported, but worked when I tested it:
    You can clone the repos next to each other and reference the project across the repo boundary. This is not intended to be supported by the tools (we will in fact block you when you try to add a reference to a project outside the solution). But if you add it to the docker-compose.yaml the same as any other project (and include the project in your solution). It did work when I tested it. I can't stress enough this is not formally supported and should only be considered if git sub modules are a non started for you.

    Just getting silly:
    Full disclosure I didn't have time to make a whole test version of this, but there is no reason I can think of that it wouldn't work. That said it is the kookiest of the options.
    You can add a dummy ASP.NET project, and then have its Dockerfile use the actual image as the base to pull in the real code you want. You then can use the labels from https://learn.microsoft.com/en-us/visualstudio/containers/docker-compose-properties?view=visualstudio#docker-compose-file-labels in a file named docker-compose.vs.debug.yml to control the app we start for debugging. The biggest risk I can see here is the volume mounts we use to speed up debugging accidentally overriding the app code from the real base image. The best mitigation would be to set DockerDevelopmentMode to Regular which causes VS to do a full image build and then you can simply not copy in the code from your dummy app in the Dockerfile.
    I don't recommend this option, but if the others don't work for you, it should be an option.

  3. AHarman commented on Nov 12, 2026

    @AHarman
    Author

    Thanks for the suggestions here! I've not been able to pursue this for a while, but these are great suggestions and I'll be sure to give them a go soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions