Skip to content

Access to ITaskSetupContext in Frosting #3946

@devlead

Description

@devlead

Sorry to resurrect an old thread, but does someone know how to do this for a
"Frosting" project? i.e. to get access to ISetupContext.TasksToExecute.

It is exposed in FrostingTaskLifetime<T>.Setup but that is before each task.
I can't find an equivalent for FrostingLifetime<T>.Setup which is before all tasks.
Maybe I'm looking in the wrong places?

Originally posted by @lonix1 in #1772 (comment)

A quick look at the code, it looks like currently, the SetupContext isn't passed to the Frosting setup, adding it to IFrostingLifetime / IFrostingSetup would be a breaking change, so maybe first fixed in the next mayor release, or at least some more thought will need to go into it.

_engine.RegisterSetupAction(info => _setup.Setup(_context));

like it is for the teardown

_engine.RegisterTeardownAction(info => _teardown.Teardown(_context, info));

A dirty workaround, in this case, could be to register the setup task yourself.

This could be done by injecting a custom setup task in IoC and adding it and ICakeEngine to your own custom context. that could look something like

using System.Threading.Tasks;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Frosting;
using Microsoft.Extensions.DependencyInjection;

public static class Program
{
    public static int Main(string[] args)
    {
        return new CakeHost()
            .ConfigureServices(services => services.AddSingleton<CustomBuildSetup>())
            .UseContext<BuildContext>()
            .Run(args);
    }
}

public class BuildContext : FrostingContext
{
    public BuildContext(ICakeContext context, ICakeEngine cakeEngine, CustomBuildSetup customBuildSetup)
        : base(context)
    {
        cakeEngine.RegisterSetupAction(setupContext => customBuildSetup.Setup(this, setupContext));
    }
}

public class CustomBuildSetup
{
    public void Setup(BuildContext buildContext, ISetupContext setupContext)
    {
        buildContext.Log.Information("Custom setup found {0} tasks starting with {1}", setupContext.TasksToExecute.Count, setupContext.TargetTask.Name);
    }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions