cake-build / cake

:cake: Cake (C# Make) is a cross platform build automation system.
https://cakebuild.net
MIT License
3.9k stars 726 forks source link

(Frosting) RunTarget #2890

Open niqhtei opened 7 years ago

niqhtei commented 7 years ago

Is there a way to explicitly run a specific target just like in .cake file you call RunTarget("whetever")? Looks like Target string property is in CakeHostOptions, but couldnt find a way to configure those options.

mderriey commented 7 years ago

Hey @byyyt,

You can absolutely do it by using the Target parameter of the build.ps1 PowerShell script provided. It could look something like:

.\build.ps1 -Target Whatever

The PowerShell script takes care of passing this parameter (along with others) to the .NET Core application, as you can see here.

niqhtei commented 7 years ago

Yeah I know you can pass the target in via parameters. But can you do it from code, like with .cake script? Explicitly call specific task.

mderriey commented 7 years ago

What is the use case? Do you want to determine at runtime which top-level task you want to execute?

patriksvensson commented 7 years ago

@byyyt Targets are parsed from the arguments sent to the application. I guess that we could add a SetTarget overload to the CakeHostBuilder, but I would like to know the use case for this.

niqhtei commented 7 years ago

@patriksvensson Yes I looked up the source code for it. Passing the target via argument currently. I have no specific use case that would make a "good" argument to implement SetTarget overload. I was just converting from .cake script files and was looking and hoping for parity.

Maybe going the argument way makes it less clear what the entry point for the whole build process is. Once I open the build project, look at the Lifetime Setup, it is not clear where the build actually starts. Setting up task dependencies via attributes dont help too much either, since you have to first know which tasks is going to be the target task, then trace back the task dependencies down the tree till you hit the first task that is going to be executed. However, this is whole another topic.

mikey123-cmd commented 1 month ago

I am not sure if this was resolved, but I am looking for a way to force one of the defined tasks to run along its dependencies, based on a condition, just like RunTarget in cake.

I am aware that the target could be send from the command line i.e -Target=Task1, but I would like this to be determined at the runtime of the cake frosting code.