XdtTransformationAlias.

XdtTransformConfig(ICakeContext, FilePath, FilePath, XdtSource, XdtTransformationSettings) Method

Summary

Transforms configuration files using XDT Transform library using the specified transformation source. The transformation source can be a file, a transform document, or a document fragment.

Syntax

public static void XdtTransformConfig(this ICakeContext context, FilePath sourceFile, FilePath targetFile, XdtSource transformation, XdtTransformationSettings settings = null)

Examples

 var target = Argument("target", "Default");

 Task("TransformConfig")
   .Does(() => {

     // specifying a fragment like this will infer and create a full document XML structure.
     // use XdtDocumentSource to pass a fully qualified XML document structure
     var transformFragment = "<appSettings><add key="key-name" value="key-value" xdt:Locator="Match(key)" xdt:Transform="SetAttributes" /></appSettings>";
     var sourceFile = File("web.config");
     var targetFile = File("web.target.config");
     var settings = new XdtTransformationSettings().UseDefaultLogger();

     XdtTransformConfig(sourceFile, targetFile, new XdtFragmentSource(transformFragment), settings);
     
     if(settings.Logger.HasWarning)
     {
         var warnings = settings.Logger.Log
                           .Where(entry => entry.MessageType == XdtTransformationLog.Warning)
                           .Select(entry => entry.ToString());
                           
         var concatWarnings = string.Join("\r\n", warnings);
         
         throw new Exception("Transformation has warnings:\r\n" + concatWarnings);
     }
 });

 RunTarget(target);

Attributes

Type Description
CakeMethodAliasAttribute

Parameters

Name Type Description
context ICakeContext The context.
sourceFile FilePath Source file to be transformed.
targetFile FilePath Output file name for the transformed file.
transformation XdtSource The transformation to apply.
settings XdtTransformationSettings The settings to use during transformation. Specifying null will throw any errors encountered.

Return Value

Type Description
void