dotnet / sdk-container-builds

Libraries and build tooling to create container images from .NET projects using MSBuild
https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container
MIT License
181 stars 39 forks source link

PublishContainer doesn't traverse the project tree (Microsoft.Build.Traversal) #594

Open oats4goats opened 2 months ago

oats4goats commented 2 months ago

Hey!

I use a .proj file in the root (generated by dotnet-affected tooling) to build and publish the affected projects in my tree.

I'm now exploring the PublishContainer target for my CI pipeline. And it seems to be checking isPublishable and EnableSdkContainerSupport props in the said .proj file (in the root) which are false by default and then skips publishing the containers altogether without traversing the tree.

Publishing the projects inside the tree works just fine. Is it an intended behavior?

Thanks for looking into this!

-- MItya

baronfel commented 2 months ago

You'd need to ask the traversal SDK folks why the target isn't forwarded along to the child projects.

oats4goats commented 2 months ago

Got it! Thanks. Will report back.

baronfel commented 2 months ago

Great! Interested in hearing what they think - in general if an action works for a solution we should be able to support it for a traversal project as well.

baronfel commented 1 month ago

@jeffkl I'm guessing this is because the Traversal targets have explicit support for a key set of MSBuild targets that they forward along to ProjectReferences, and the PublishContainer target isn't one of those. That sound about right?

jeffkl commented 1 month ago

@baronfel that is correct, only a handful of targets are implemented in Traversal: https://github.com/microsoft/MSBuildSdks/blob/main/src/Traversal/Sdk/Traversal.targets#L135-L284

When building a solution, MSBuild generates a metaproj on-the-fly and any target not already declared it dynamically generates one for. I wonder if MSBuild should have a feature to do this for Traversal projects as well?

But it wouldn't be that hard to add the PublishContainer target to Traversal either. Someone just needs to do it.