Closed sitty closed 8 years ago
Hello @sitty!
Cake already have XDT transform support. Check out http://cakebuild.net/dsl/xml for more information.
/ Patrik
@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?
Not currently as far as I'm aware. I wrote a custom task to as much myself.
@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:
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>
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.
@phillipsj thank you.
Is there any plan to support config file xdt transforms. You could probably use Config Transformation Tool http://ctt.codeplex.com/