Not possible without writing code.
However, my current solution is to extent the XDT Transform library, by basically following the link: Extending XML (web.config) Config transformation
And here is my example of CommentAppend
, CommentPrepend
which take comment text as input parameter, as I believe otherwise Insert
itself can't work as the comment you would put your xdt:Transform="Insert"
will be ignored by XDT Transform as it is comment.
internal class CommentInsert: Transform
{
protected override void Apply()
{
if (this.TargetNode != null && this.TargetNode.OwnerDocument != null)
{
var commentNode = this.TargetNode.OwnerDocument.CreateComment(this.ArgumentString);
this.TargetNode.AppendChild(commentNode);
}
}
}
internal class CommentAppend: Transform
{
protected override void Apply()
{
if (this.TargetNode != null && this.TargetNode.OwnerDocument != null)
{
var commentNode = this.TargetNode.OwnerDocument.CreateComment(this.ArgumentString);
this.TargetNode.ParentNode.InsertAfter(commentNode, this.TargetNode);
}
}
}
And the input web.Release.config
:
<security xdt:Transform="CommentPrepend(comment line 123)" >
</security>
<security xdt:Transform="CommentAppend(comment line 123)" >
</security>
And the output:
<!--comment line 123--><security>
<requestFiltering>
<hiddenSegments>
<add segment="NWebsecConfig" />
<add segment="Logs" />
</hiddenSegments>
</requestFiltering>
</security><!--comment line 123-->
I am currently using Reflector to look at Microsoft.Web.XmTransform comes with Visual Studio V12.0 to figure out how it works, but probably it's better to look at the source code itself