cake-build / cake

:cake: Cake (C# Make) is a cross platform build automation system.
https://cakebuild.net
MIT License
3.89k stars 726 forks source link

Config transforms #321

Closed sitty closed 8 years ago

sitty commented 9 years ago

Is there any plan to support config file xdt transforms. You could probably use Config Transformation Tool http://ctt.codeplex.com/

patriksvensson commented 9 years ago

Hello @sitty!

Cake already have XDT transform support. Check out http://cakebuild.net/dsl/xml for more information.

/ Patrik

sitty commented 9 years ago

@patriksvensson All the documentation seems to say it for xsl transforms which I think is an an overkill for simple config transforms. Is there a way you can do xdt transfroms like http://www.asp.net/mvc/overview/deployment/visual-studio-web-deployment/web-config-transformations using the current xml transform task?

RichiCoder1 commented 9 years ago

Not currently as far as I'm aware. I wrote a custom task to as much myself.

patriksvensson commented 9 years ago

@sitty Ok. It was @devlead that wrote the XSL transformation stuff, so maybe he has some input on this.

@RichiCoder1 Something you would like to share? :smile:

devlead commented 9 years ago

Well web.config XDT could be achieved with following cake script

#addin "Microsoft.Web.Xdt"
using Microsoft.Web.XmlTransform;
var sourceFile      = File("web.config");
var transformFile   = File("web.release.config");
var targetFile      = File("web.target.config");
using(var document  = new XmlTransformableDocument { PreserveWhitespace = true })
using(var transform = new Microsoft.Web.XmlTransform.XmlTransformation(transformFile))
{
    document.Load(sourceFile);

    if(!transform.Apply(document))
    {
        throw new Exception(
                string.Format(
                    "Failed to transform \"{0}\" using \"{1}\" to \"{2}\"",
                    sourceFile,
                    transformFile,
                    targetFile
                    )
                );
    }

    document.Save(targetFile);
}

Sample web.config

<?xml version="1.0"?>
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.5" />
    </system.web>
</configuration>

Sample web.release.config (transform document)

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
</configuration>

Sample web.target.config (output document)

<?xml version="1.0"?>
<configuration>
    <system.web>
        <compilation targetFramework="4.5" />
    </system.web>
</configuration>
phillipsj commented 8 years ago

This is an old ticket, but I stumbled across it for the same reason. I took the example code here and bundled it up into an addin and published it to Nuget to make it easier. I didn't think you all would want the extra dependency in core. If you do, I am more than happy to submit a pull request.

Cake.XdtTransform Addin

ayoung commented 7 years ago

@phillipsj thank you.