XdtTransformationAlias.

XdtTransformConfig(ICakeContext, 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, XdtSource transformation, XdtTransformationSettings settings = null)

Examples

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

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

     var transformFragment = "<appSettings><add key="key-name" value="key-value" xdt:Locator="Match(key)" xdt:Transform="SetAttributes" /></appSettings>";
     var sourceFile = File("web.config");
     var settings = new XdtTransformationSettings().UseDefaultLogger();

     XdtTransformConfig(sourceFile, 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. This is also the target file, indicating an in-place transform.
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