Skip to content

Instantly share code, notes, and snippets.

@DanijelMalik
Created January 6, 2017 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanijelMalik/d8b5b12e60b4fbca9a0fa6f936c70143 to your computer and use it in GitHub Desktop.
Save DanijelMalik/d8b5b12e60b4fbca9a0fa6f936c70143 to your computer and use it in GitHub Desktop.
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