dotnet publish: AfterTargets="AfterPublish" triggers before publish is complete

catmanjan 61 Reputation points
2025-02-26T23:21:37.83+00:00

Can someone look at this Github issue and help resolve it for us?

https://github.com/dotnet/sdk/issues/46999

Azure Container Registry
Azure Container Registry
An Azure service that provides a registry of Docker and Open Container Initiative images.
486 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 29,851 Reputation points Microsoft Employee
    2025-03-04T19:37:08.04+00:00

    Hey @catmanjan

    We did circle with the team internally; and the build process is working as expected. The <Target /> definitions you defined are evaluated by MSBuild as part of a core process and publish steps, i.e. <DockerPublish/> are executed post the core step. The way to think of it, VS:

    • Pre: verify pre-requisites
    • Core: build (projects, images) and execute targets
    • Post: push the image

    That's why you're seeing this type of experience. The VS IDE isn't suitable for this type of customizable build. Having a CI/CD pipeline would be the best preferable option, but I know you've stated using the IDE for your build and publish.

    To that end, the only way I know of to get around this is separating your build and publish into two or more different proj files. You'll want one to reference the project being built and have those artifacts saved to a destination folder and pushed and a second one to execute your kubectl commands.

    Feel free though pass feedback to the team about this issue. The team will capture the feedback and evaluate it. You can always submit feedback and issues through the Visual Studio IDE; see Report a problem with Visual Studio - Visual Studio (Windows) | Microsoft Learn.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.