Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Central Package Management break Visual Studio docker integration #11972

Closed
edumserrano opened this issue Jul 15, 2022 · 10 comments
Closed
Assignees
Labels
Area:RestoreCPM Central package management Priority:2 Issues for the current backlog. Type:Bug

Comments

@edumserrano
Copy link

edumserrano commented Jul 15, 2022

NuGet Product Used

Other/NA

Product Version

tested with: nuget 6.2.1.7, dotnet 6.0.302, Visual Studio 17.2.6 as well as with nuget 6.3.0.114, dotnet 6.0.400-preview.22330.6 and Visual Studio 17.3 Preview 3

Worked before?

It works when Central Package Management is disabled.

The bug happens when you can create, for instance, an ASP.NET Core Web API project and enable Docker integration. This allows you to have a profile that launches the application on a Docker container. The expected behavior is:

  • Create an ASP.NET Core Web API project with Docker enabled.
  • Run the Web API app using the Docker profile from the launchSettings.json.
  • Visual Studio will build and run the Docker container and attach the debugger to the app running on the Docker container.

Impact

Other

Repro Steps & Context

Create an ASP.NET Core Web API project with Docker integration enabled and enable Central Package Management. Then when you try to run the application on a Docker container you get a prompt from Visual Studio which doesn't let the process carry on as expected. The bug is:

  • Create an ASP.NET Core Web API project with Docker enabled.
  • Enable Central Package Management as described in Introducing Central Package Management.
  • Run the Web API app using the Docker profile from the launchSettings.json.
  • Visual Studio displays a prompt to install a NuGet which is already installed.
  • Even if you say you want to install the package the debug process is aborted without further information on the output. You just get another prompt saying it failed.

I've created a repo edumserrano/example-cpm-docker that reproduces this bug. It's a solution with only one Web API project. The README of the repo contains all the information on how to run the code.

Verbose Logs

N/A
@nkolev92
Copy link
Member

@edumserrano

Can you please provide information about the failure in this bug itself.
It's not immediately clear what the problem is.

@edumserrano
Copy link
Author

@nkolev92 did you see the The README of the repo? It explains what happens and expected behavior.

In short, if you enable CPM you can not run a VS solution with a docker launch option.

@nkolev92
Copy link
Member

Hey @edumserrano

Yes, I did look at the readme, my comment was about including the expected/actual information in this issue itself.

I'm not saying you'd do this, but sometimes repos go private and we lose the information about the bug itself and we can't act on it.
For that reason we prefer as much of the details as possible in the issue body itself.

@edumserrano
Copy link
Author

@nkolev92 Apologies, I've updated the body of the issue. Let me know if you need anything else.

@edumserrano
Copy link
Author

edumserrano commented Aug 30, 2022

Hey, I'm just curious if you guys already did some planning on this and perhaps have an idea on when you plan on tackling it? As in, perhaps considering it for version VS 17.4? Besides curiosity I'm asking cause I want to use CPM but I ended up disabling it for my team's project due to this bug.

@jeffkl
Copy link
Contributor

jeffkl commented Aug 30, 2022

@edumserrano sorry I'm late to reply here, I was out of vacation. Thanks for the excellent amount of details on this issue. I'm still learning docker so correct me if I'm wrong but won't we need to copy more than just the .csproj? Like Directory.Packages.props for example and any other build logic that takes part in restore/build?

https://github.com/edumserrano/example-cpm-docker/blob/440138471c553d43755317db302bbeed34ef8705/CentralPackageManagementWithDocker/Dockerfile#L10

I did clone your example repo but of course it works for me. I am able to load the solution and debug without prompts. I also tried creating a new ASP .NET Core Web App with Docker support enabled and it seems to work.

@edumserrano
Copy link
Author

edumserrano commented Aug 31, 2022

@jeffkl No worries, hope you had a great time =)

You are correct in saying that the Dockerfile should contain everything it needs to do the restore which normally would include files like the Directory.Packages.props in this scenario.

However, I'm not building the Dockerfile from the command line, if I were then yes I would have to include that COPY instruction. I'm running from Visual Studio which only builds the base stage of the Dockerfile the rest of the file is for when the users actually want to build the full image for whatever purpose (ie: publishing to a registry, testing something, running locally outside of VS, etc).

For more information see How to customize Docker containers in Visual Studio:

In Fast mode, Visual Studio calls docker build with an argument that tells Docker to build only the base stage (you can change that by setting the MSBuild property, DockerfileFastModeStage, described later). Visual Studio handles the rest of the process without regard to the contents of the Dockerfile.

You can check the above in Visual Studio by going to the Output window and selecting view output from Container Tools. In there, once you try to debug the example repo from Visual Studio you will see something like:

note that the docker build commmand issued by Visual Studio has the --target base flag meaning only that stage of the Dockerfile gets build.

Starting up container(s)...
docker build -f "D:\Dev\edumserrano\example-cpm-docker\CentralPackageManagementWithDocker\Dockerfile" --force-rm -t centralpackagemanagementwithdocker:dev --target base  --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=CentralPackageManagementWithDocker" "D:\Dev\edumserrano\example-cpm-docker" 

I probably should have updated the rest of the Dockerfile to avoid any confusion but since this was enough to reproduce the problem I missed that part.

Are you saying you do not get the error message if you try to debug the solution in the example repo using Visual Studio?

P.S. - I'm now running VS 17.3.3 and still getting the error.

@jeffkl
Copy link
Contributor

jeffkl commented Aug 31, 2022

@edumserrano its interesting that there are differences when building in Visual Studio. That seems unreliable if things work differently depending on the build environment. But again, I'm so new to Docker so I must still be missing something.

Are you saying you do not get the error message if you try to debug the solution in the example repo using Visual Studio?

Yes, that is correct, I am not able to reproduce the issue but I finally figured out why. I'm running a preview version of Visual Studio 2022 17.4. I am able to reproduce the issue in Visual Studio 2022 17.3.

Can you try installing 17.4 Preview and see if it happens still? https://visualstudio.microsoft.com/vs/preview/#download-preview

It looks like someone maybe fixed it...

@edumserrano
Copy link
Author

@jeffkl I can confirm this is not happening on VS 17.4.0 Preview 1.
Feel free to close this bug report, I guess it might be nice if you could link it to the 17.4 release or to the PR/commit that fixed this issue just for history sake.

@jeffkl
Copy link
Contributor

jeffkl commented Aug 31, 2022

Okay great, I'm closing this as a duplicate of microsoft/DockerTools#342 then which I finally found

@jeffkl jeffkl closed this as completed Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:RestoreCPM Central package management Priority:2 Issues for the current backlog. Type:Bug
Projects
None yet
Development

No branches or pull requests

3 participants