Created
January 6, 2017 03:41
-
-
Save DanijelMalik/d8b5b12e60b4fbca9a0fa6f936c70143 to your computer and use it in GitHub Desktop.
Transforms XML files e.g. Web.Release.config to Web.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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