I've found need to be able to pass in a random transformations that aren't on the file system.
In general, I've just created a lightweight method right in my .cake
file that exposes TransformConfig(FilePath file, string transformFragment)
where the transformFragment
is a well-formed <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
transformation string.
If there seems to be value in contributing that to the project, I'd gladly put something together.
It seems worthwhile to provide an appropriate overload for all the existing methods so that all the current functionality (loggers, etc.) can be enjoyed. The problem with this is the conversion between string
and FilePath
and any potential to break existing build scripts.
i.e.,
// existing
XdtTransformConfig(sourceFile, transformFile, targetFile);
// refactored for fragment -- this would collide
XdtTransformConfig(sourceFile, targetFile, transformString);
So my question becomes - what do you think is a good pattern for this?
Created named overloads?
Try to converge on a pattern?
It seems awkward to call something XdtTransformConfigUsingFragmentWithLogger
or similar, and my own leaning would be to attempt to converge on a more unified set of method names.
My one thought might be to distill something like this ..
[CakeMethodAlias]
public static void XdtTransformConfig(this ICakeContext context, FilePath sourceFile, FilePath targetFile, XdtTransformOptions options) {
// impl
}
public sealed class XdtTransformOptions
{
public FilePath TransformFile { get; set; }
public string XmlTransformation { get; set; }
public IXmlTransformationLogger Logger { get; set; }
}
My one hesitation there is that we'd have to account for users specifying both the file + the xml string, and that speaks to precedence, which I think should be avoided. Other approaches could be just to strongly type the XmlTransform
type as a wrapper around the string
and allow implicit/explicit conversion so that it Just Worksβ’
public static void XdtTransformConfig(FilePath source, FilePath target, XmlTransform transform)
Any thoughts or preferences on how to approach?