CommonBuildToolset / CBT.Modules

Modules for CBT
MIT License
9 stars 5 forks source link

Allow specifying targets for ProjectFiles #258

Closed aelij closed 4 years ago

aelij commented 5 years ago

Currently when specifying a <ProjectFile /> for traversal, only the default targets are built. If we want to add other targets, we need to modify the project file, add conditions, etc.

It would be very useful to be able to specify the targets directly in the traversal definition, e.g.:

<ProjectFile Targets="Package" />
dfederm commented 5 years ago

Typically you would just set the default target in the proj file itself.

Eg:

<Project ToolsVersion="14.0" DefaultTargets="Package" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" InitialTargets=";ValidateMSBuildFiles">
aelij commented 5 years ago

Yes, but that's exactly what I'm trying to avoid. Without this option, you'd have to customize the retail experience (VS) and try to come up with all sorts of conditions so it would only build these targets during traversal and not in VS.

Is there a downside to this suggestion? I think it would be pretty simple to implement.

dfederm commented 5 years ago

I don't think it does customize the VS experience. VS still uses /t:Build to build and so the default targets would not be run. The default targets would only run when calling MSBuild directly from the command-line, which is your scenario effectively.

ohadschn commented 5 years ago

Still, editing MSBuild project files directly deviates from the retail experience. If the build admin can provide an external dirs.proj that allows developers to be oblivious to the underlying targets at play, that's a win in my book...

jeffkl commented 5 years ago

I think this is a good idea. I have a few questions:

  1. If a dirs.proj specified a target to build, that same project would build differently when building the project directly, is that okay?
  2. The target that you specify would only be used when building the Build target of the dirs.proj. So if you did msbuild dirs.proj /t:Foo, it would still run the Foo target for every project. But if you did msbuild dirs.proj or msbuild dirs.proj /t:Build, it would run the custom target. Is that okay?
aelij commented 5 years ago

IMO:

If a dirs.proj specified a target to build, that same project would build differently when building the project directly, is that okay?

Yes

So if you did msbuild dirs.proj /t:Foo, it would still run the Foo target for every project

I think this should be controllable somehow. Maybe using a property?

ohadschn commented 5 years ago

VS still uses /t:Build to build and so the default targets would not be run

I can say for certain that this is not always the case. For my ccproj (on CBT), Visual Studio happily runs the Publish target if specified in the DefaultTargets (msbuild /t:build does not).