cake
cake copied to clipboard
Context data can't handle data base class
Prerequisites
- [X] I have written a descriptive issue title
- [X] 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
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");