Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Transforms XML files e.g. Web.Release.config to Web.config
param(
[string] $SourceFile,
[string] $TargetFile
)
if (!$SourceFile -or !(Test-Path -path $SourceFile -PathType Leaf)) {
throw "File not found. $xml";
}
if (!$TargetFile -or !(Test-Path -path $TargetFile -PathType Leaf)) {
throw "File not found. $TargetFile";
}
Add-Type -LiteralPath "Microsoft.Web.XmlTransform.dll"
$xmldoc = New-Object Microsoft.Web.XmlTransform.XmlTransformableDocument;
$xmldoc.PreserveWhitespace = $true
$xmldoc.Load($SourceFile);
$transf = New-Object Microsoft.Web.XmlTransform.XmlTransformation($TargetFile);
if ($transf.Apply($xmldoc) -eq $false)
{
throw "Transformation failed."
}
$xmldoc.Save($SourceFile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment