msbuild icon indicating copy to clipboard operation
msbuild copied to clipboard

Choose/When/Otherwise in Targets

Open dasMulli opened this issue 7 years ago • 7 comments

<Choose>/<When>/<Otherwise> is a nice feature that allows replacing complex conditions with what is effectively a switch-case-default but can only be used on the project level and not within targets.

Can this be changed to work within targets? This would theoretically conflict with tasks being named Choose, are there any ways to deal with this? - like (and I feel bad suggesting this) optional xml namespace for <MSBuild:Choose> and prefer a task named Choose if defined.

dasMulli avatar May 04 '17 05:05 dasMulli

@rainersigwald @jeffkl @cdmihai is this feasible at all? I so, I'd hope to see this in 16.0. If not, go ahead and close it as "won't implement".

dasMulli avatar Aug 09 '18 06:08 dasMulli

I don't have a strong objection to this, other than the conflict-with-task one. But it's not very high on my priority list, personally. Anybody else feel more strongly about it?

rainersigwald avatar Aug 14 '18 20:08 rainersigwald

Implementation wise it will be interesting, since the current design accepts only tasks within targets (properties and items in targets are actually implemented as tasks). But shouldn't be too hard, probably involves implementing a Choose IntrinsicTask .

cdmihai avatar Aug 14 '18 21:08 cdmihai

Implementing a choose intrinsic task seems to be promising, I got a prototype at https://github.com/dasMulli/msbuild/tree/feature/choose-in-targets (Compare)

If there is interest in taking this as a community contribution I could invest more work into it.

dasMulli avatar Sep 09 '18 12:09 dasMulli

Took a quick look over it and looks good! Feel free to open it up as a WIP PR to get more feedback.

My take on it:

  • not sure whether to allow task executions, or to restrict it to only what's allowed in the choose elements outside of targets.
  • add more tests. To find the relevant tests to duplicate (or transform them into [Theory]) you can search for <choose in all the *_Tests.cs files. But do send the WIP PR before you do this.

cdmihai avatar Sep 12 '18 00:09 cdmihai

Team triage: #3851 is a solid-looking implementation of this, but we currently think we should wait for a major release to add this type of language feature. If we want to take this for 17.0, it should definitely start with reviving #3851.

rainersigwald avatar Jul 09 '19 20:07 rainersigwald

Hello there ;-), what's the curent status of this issue?

voroninp avatar Apr 27 '24 08:04 voroninp