Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context data can't handle data base class #4049

Open
2 tasks done
McDoit opened this issue Nov 5, 2022 · 1 comment
Open
2 tasks done

Context data can't handle data base class #4049

McDoit opened this issue Nov 5, 2022 · 1 comment

Comments

@McDoit
Copy link
Contributor

McDoit commented Nov 5, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

Cake runner

Cake .NET Tool

Cake version

2.3.0

Operating system

Windows

Operating system architecture

64-Bit

CI Server

No response

What are you seeing?

I'm experimenting a bit with multi-layered cake files
Currently working on putting all the base building/testing in a single cake file, and use that for more specific packing tasks in other files
Running inhertiance between the setuped implementation and an abstract base class in the base cake file gives the following error

An error occurred when executing task 'Build'.
Error: The context data has not been setup.

That seems to indicate that it doesn't consider or support reading context data based on inherited classes?

What is expected?

To be able to use data in a base class, in Does calls typed to the baseclass

Steps to Reproduce

Base.cake file:

internal abstract class BaseCake
{
    public FilePath SolutionFile { get; set; }
}

var buildTask = Task("Build")
    .Does<BaseCake>(bc =>
{
    var settings = new DotNetBuildSettings
    {
        Configuration = "Debug"
    };

    DotNetBuild(bc.SolutionFile.FullPath, settings);
});

Pacakge.cake

#load Base.cake

internal class PackageCake : BaseCake
{
}

Setup<PackageCake>(ctx => {
    var pc = new PackageCake(); //code
    return pc;
});

var packTask = Task("Pack")
    .IsDependentOn(buildTask)
    .Does<PackageCake>(pc =>
{
    //code
});

This will casue the Package.cake to fail with

An error occurred when executing task 'Build'.
Error: The context data has not been setup.

Output log

No response

@devlead
Copy link
Member

devlead commented Nov 5, 2022

This is by design, you can register multiple types by running Setup multiple with different types, if base type was registered this wouldn't be possible.

But you could opt-in to register your base type, i.e. something like below

internal abstract class BaseCake
{
    public FilePath SolutionFile { get; set; }
}

var buildTask = Task("Build")
    .Does<BaseCake>(bc =>
{
    var settings = new DotNetBuildSettings
    {
        Configuration = "Debug"
    };

    DotNetBuild(bc.SolutionFile.FullPath, settings);
});


internal class PackageCake : BaseCake
{
}

{
    var pc = new PackageCake{
        SolutionFile = "MySolution.sln"
    };//code
    Setup(ctx => pc);
    Setup<BaseCake>(ctx => pc);
}

var packTask = Task("Pack")
    .IsDependentOn(buildTask)
    .Does<PackageCake>(pc =>
{
    //code
});

RunTarget("Pack");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants