@@ -179,13 +179,17 @@ public void RegisterTaskTeardownAction<TData>(Action<ITaskTeardownContext, TData
179179 /// </summary>
180180 /// <param name="context">The context.</param>
181181 /// <param name="strategy">The execution strategy.</param>
182- /// <param name="target ">The target to run .</param>
182+ /// <param name="settings ">The execution settings .</param>
183183 /// <returns>The resulting report.</returns>
184- public async Task < CakeReport > RunTargetAsync ( ICakeContext context , IExecutionStrategy strategy , string target )
184+ public async Task < CakeReport > RunTargetAsync ( ICakeContext context , IExecutionStrategy strategy , ExecutionSettings settings )
185185 {
186- if ( target == null )
186+ if ( settings == null )
187187 {
188- throw new ArgumentNullException ( nameof ( target ) ) ;
188+ throw new ArgumentNullException ( nameof ( settings ) ) ;
189+ }
190+ if ( string . IsNullOrWhiteSpace ( settings . Target ) )
191+ {
192+ throw new ArgumentException ( "No target specified." , nameof ( settings ) ) ;
189193 }
190194
191195 if ( strategy == null )
@@ -200,6 +204,7 @@ public async Task<CakeReport> RunTargetAsync(ICakeContext context, IExecutionStr
200204 var graph = CakeGraphBuilder . Build ( _tasks ) ;
201205
202206 // Make sure target exist.
207+ var target = settings . Target ;
203208 if ( ! graph . Exist ( target ) )
204209 {
205210 const string format = "The target '{0}' was not found." ;
@@ -228,26 +233,18 @@ public async Task<CakeReport> RunTargetAsync(ICakeContext context, IExecutionStr
228233
229234 PerformSetup ( strategy , context , targetNode , orderedTasks , stopWatch , report ) ;
230235
231- foreach ( var task in orderedTasks )
236+ if ( settings . Exclusive )
232237 {
233- // Is this the current target?
234- var isTarget = task . Name . Equals ( target , StringComparison . OrdinalIgnoreCase ) ;
235-
236- // Should we execute the task?
237- var skipped = false ;
238- foreach ( var criteria in task . Criterias )
239- {
240- if ( ! ShouldTaskExecute ( context , task , criteria , isTarget ) )
241- {
242- SkipTask ( context , strategy , task , report , criteria ) ;
243- skipped = true ;
244- break ;
245- }
246- }
247-
248- if ( ! skipped )
238+ // Execute only the target task.
239+ var task = _tasks . FirstOrDefault ( x => x . Name . Equals ( settings . Target , StringComparison . OrdinalIgnoreCase ) ) ;
240+ await RunTask ( context , strategy , task , target , stopWatch , report ) ;
241+ }
242+ else
243+ {
244+ // Execute all scheduled tasks.
245+ foreach ( var task in orderedTasks )
249246 {
250- await ExecuteTaskAsync ( context , strategy , stopWatch , task , report ) . ConfigureAwait ( false ) ;
247+ await RunTask ( context , strategy , task , target , stopWatch , report ) ;
251248 }
252249 }
253250
@@ -265,6 +262,29 @@ public async Task<CakeReport> RunTargetAsync(ICakeContext context, IExecutionStr
265262 }
266263 }
267264
265+ private async Task RunTask ( ICakeContext context , IExecutionStrategy strategy , CakeTask task , string target , Stopwatch stopWatch , CakeReport report )
266+ {
267+ // Is this the current target?
268+ var isTarget = task . Name . Equals ( target , StringComparison . OrdinalIgnoreCase ) ;
269+
270+ // Should we execute the task?
271+ var skipped = false ;
272+ foreach ( var criteria in task . Criterias )
273+ {
274+ if ( ! ShouldTaskExecute ( context , task , criteria , isTarget ) )
275+ {
276+ SkipTask ( context , strategy , task , report , criteria ) ;
277+ skipped = true ;
278+ break ;
279+ }
280+ }
281+
282+ if ( ! skipped )
283+ {
284+ await ExecuteTaskAsync ( context , strategy , stopWatch , task , report ) . ConfigureAwait ( false ) ;
285+ }
286+ }
287+
268288 private void PerformSetup ( IExecutionStrategy strategy , ICakeContext context , CakeTask targetTask ,
269289 CakeTask [ ] tasks , Stopwatch stopWatch , CakeReport report )
270290 {
@@ -283,8 +303,7 @@ private void PerformSetup(IExecutionStrategy strategy, ICakeContext context, Cak
283303 }
284304 }
285305
286- private static bool ShouldTaskExecute ( ICakeContext context , CakeTask task , CakeTaskCriteria criteria ,
287- bool isTarget )
306+ private static bool ShouldTaskExecute ( ICakeContext context , CakeTask task , CakeTaskCriteria criteria , bool isTarget )
288307 {
289308 if ( ! criteria . Predicate ( context ) )
290309 {
0 commit comments