microsoft / DockerTools

Tools For Docker, including Visual Studio Provisioning and Publishing
Other
173 stars 26 forks source link

VisualStudio 2022 - docker compose - debugging does not work when dockerfile is not in default location #355

Closed kicaj29 closed 1 year ago

kicaj29 commented 1 year ago

I created a simple solution .NET 6 and 2 WebApi projects. I added docker compose support to the solution for both projects. So it looks like this:

DockerInVS
  docker-compose*
  WebApp1
    Dockerfile
  WebApp2
    MyDockerfile

Both projects targets linux containers.

For WebApp2 additionally I updated csproj with <DockerfileFile>.\MyDockerfile</DockerfileFile> and docker-compose.override.yml with dockerfile: WebApp2/MyDockerfile because I do not use default docker file name. Such configuration works fine - I can run it and debug it.

The bug

When I place MyDockerfile in a subfolder CI so it looks like this

DockerInVS
  docker-compose*
  WebApp1
    Dockerfile
  WebApp2
    CI
      MyDockerfile

and I update the settings to these values <DockerfileFile>.\CI\MyDockerfile</DockerfileFile> and dockerfile: WebApp2/CI/MyDockerfile then I cannot debug WebApp2 project. Also I see that WebApp2 is run differently then WebApp1: WebApp1 has command tail -f /dev/null but WebApp2 has command dotnet WebApp2.dll.

I checked in docs https://learn.microsoft.com/pl-pl/visualstudio/containers/container-build?WT.mc_id=visualstudio_containers_aka_containerfastmode&view=vs-2022#container-entry-point and it looks that dotnet webapp.dll means that debugger has not been attached.

Any ideas how to make debugging working when a docker file is placed in another folder?

Docs https://learn.microsoft.com/en-us/visualstudio/containers/container-msbuild-properties?view=vs-2022 say that DockerfileFile setting can be also a path: "Describes the default Dockerfile that will be used to build/run the container for the project. This can be a path as well."

NCarlsonMSFT commented 1 year ago

@kicaj29 Sorry for the slow response, this is currently the specified behavior for how the .dcproj connects services to projects for debugging. We do have an item on our backlog to revisit making this more flexible, but I don't have a timeline for when this may change.

ggirard07 commented 1 year ago

Possible duplicate of #343

NCarlsonMSFT commented 1 year ago

@kicaj29 Visual Studio 2022 17.5 Preview 2 now allows for specifying the label com.microsoft.visual-studio.project-name on a service to specify the associated project. For instance:

  webapplication2:
    image: ${DOCKER_REGISTRY-}webapplication2
    labels:
      com.microsoft.visual-studio.project-name: "WebApplication2"
    build:
      context: .
      dockerfile: WebApplication2/Sub/Dockerfile

Allows for debugging WebApplication2 even though the Dockerfile is in a subfolder.

Note: the label can only be set in docker-compose.yml or docker-compose.override.yml

GeovaneBelisario commented 1 year ago

Hi @kicaj29, After install Visual Studio 2022 17.5 Preview 6.0, I get a error when I try to open Manager Docker Compose Launch Settings:


Microsoft Visual Studio

An error occurred while loading the Manage Docker Compose Launch Settings dialog. Error: An item with the same key has already been added.

OK

Any idea? Thank you in advance

dbreshears commented 1 year ago

Hi @GeovaneBelisario , can you please create a new issue with steps to reproduce the issue you are seeing. thanks!

BC89 commented 1 year ago

This still seems to be an issue with Version 17.6.0 Preview 1.0. I had an existing project and was working fine with compose and now this. Funny thing it, the identity team told me to move to the latest preview and identity nuget because managed identities don't work when using a linux box for local development. Just can't win!!! Any thoughts?

BC89 commented 1 year ago

This is where the error takes you for what it's worth. image

BC89 commented 1 year ago

And then the compose manager - image

NCarlsonMSFT commented 1 year ago

@BC89 Can you provide an example of your compose file? Based on internal prodding the only case where we see this happening is when something like a label is repeated in a service.

BC89 commented 1 year ago

Compose:

`version: '3.4'

services: marketplace: image: ${DOCKER_REGISTRY-}marketplace build: context: . dockerfile: Api/Presentation/Dockerfile

marketplace-dapr: image: "daprio/daprd:latest" depends_on:

Override:

`version: '3.4'

services:

marketplace: environment:

Thanks!

NCarlsonMSFT commented 1 year ago

@BC89 both of those files parse clean... And I can't repro this with any of my local projects. Any chance there is a stack trace for the exception in the output? If not, can you attach a debugger to VS and enable a 1st chance exception for ArgumentException to get a call stack?

BC89 commented 1 year ago

It seems to me after monkeying around that the issue is in the sln and has to do with nested folders and projects. However, it's the same sln that worked fine prior to the preview upgrade.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Nathan Carlson @.> Sent: Wednesday, February 22, 2023 8:42:33 PM To: microsoft/DockerTools @.> Cc: Brendan Carroll @.>; Mention @.> Subject: [External Email] Re: [microsoft/DockerTools] VisualStudio 2022 - docker compose - debugging does not work when dockerfile is not in default location (Issue #355)

https://github.com/BC89

From @. 410-316-7820 This is an External Email from outside of KCI.


@BC89 both of those files parse clean... And I can't repro this with any of my local projects. Any chance there is a stack trace for the exception in the output? If not, can you attach a debugger to VS and enable a 1st chance exception for ArgumentException to get a call stack?

— Reply to this email directly, view it on GitHubhttps://github.com/microsoft/DockerTools/issues/355#issuecomment-1441118326, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAZFIM7BDMINEGIDY7QTSQLWY26ATANCNFSM6AAAAAAQQ26EWY. You are receiving this because you were mentioned.Message ID: @.***>

NCarlsonMSFT commented 1 year ago

@BC89 looking at all of the dictionary calls, the only other interesting things to check: Do you have any projects with the same filename or in the same folder?

BC89 commented 1 year ago

Not in the same folder but in the solution and that appears to be the culprit is odd because the dll and namespaces are different.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Nathan Carlson @.> Sent: Wednesday, February 22, 2023 10:20:50 PM To: microsoft/DockerTools @.> Cc: Brendan Carroll @.>; Mention @.> Subject: [External Email] Re: [microsoft/DockerTools] VisualStudio 2022 - docker compose - debugging does not work when dockerfile is not in default location (Issue #355)

https://github.com/BC89

From @. 410-316-7820 This is an External Email from outside of KCI.


@BC89 looking at all of the dictionary calls, the only other interesting things to check: Do you have and projects with the same filename or in the same folder?

— Reply to this email directly, view it on GitHubhttps://github.com/microsoft/DockerTools/issues/355#issuecomment-1441168024, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAZFIM3ZL2B3GIR5TDYZQDDWY3JRFANCNFSM6AAAAAAQQ26EWY. You are receiving this because you were mentioned.Message ID: @.***>

NCarlsonMSFT commented 1 year ago

@BC89 for clarification, you have multiple projects with the same filename in the solution?

BC89 commented 1 year ago

That is correct. Under different folders with different namespaces but yes.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Nathan Carlson @.> Sent: Wednesday, February 22, 2023 11:32:42 PM To: microsoft/DockerTools @.> Cc: Brendan Carroll @.>; Mention @.> Subject: [External Email] Re: [microsoft/DockerTools] VisualStudio 2022 - docker compose - debugging does not work when dockerfile is not in default location (Issue #355)

https://github.com/BC89

From @. 410-316-7820 This is an External Email from outside of KCI.


@BC89 for clarification, you have multiple projects with the same filename in the solution?

— Reply to this email directly, view it on GitHubhttps://github.com/microsoft/DockerTools/issues/355#issuecomment-1441205471, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAZFIM7VDJ6EYIUDZ3AOS3LWY3R6VANCNFSM6AAAAAAQQ26EWY. You are receiving this because you were mentioned.Message ID: @.***>

BC89 commented 1 year ago

That appears to be an issue with this version of vs. I renamed and reworked the structure a bit and now the compose is working. So looks like a regression. Thank you for assisting. Much appreciated.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Brendan Carroll @.> Sent: Wednesday, February 22, 2023 11:54:29 PM To: microsoft/DockerTools @.>; microsoft/DockerTools @.> Cc: Mention @.> Subject: Re: [External Email] Re: [microsoft/DockerTools] VisualStudio 2022 - docker compose - debugging does not work when dockerfile is not in default location (Issue #355)

That is correct. Under different folders with different namespaces but yes.

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Nathan Carlson @.> Sent: Wednesday, February 22, 2023 11:32:42 PM To: microsoft/DockerTools @.> Cc: Brendan Carroll @.>; Mention @.> Subject: [External Email] Re: [microsoft/DockerTools] VisualStudio 2022 - docker compose - debugging does not work when dockerfile is not in default location (Issue #355)

https://github.com/BC89

From @. 410-316-7820 This is an External Email from outside of KCI.


@BC89 for clarification, you have multiple projects with the same filename in the solution?

— Reply to this email directly, view it on GitHubhttps://github.com/microsoft/DockerTools/issues/355#issuecomment-1441205471, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAZFIM7VDJ6EYIUDZ3AOS3LWY3R6VANCNFSM6AAAAAAQQ26EWY. You are receiving this because you were mentioned.Message ID: @.***>

dbreshears commented 1 year ago

Going to close this issue as the original issue was fixed in 17.5. The new bug with duplicate project files names is being tracked under #371

afust003 commented 1 year ago

Hi, there is no mention of "com.microsoft.visual-studio.project-name" in the official documentation here: https://learn.microsoft.com/en-us/visualstudio/containers/docker-compose-properties?view=vs-2022 Might it have been put somewhere else?