Last active
March 27, 2017 21:49
-
-
Save anton-abyzov/952215eeffbcc7e3a5f01e615d68d09f to your computer and use it in GitHub Desktop.
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
<# | |
.SYNOPSIS | |
You can use this script to easly transform any XML file using XDT. | |
To use this script you can just save it locally and execute it. The script | |
will download it's dependencies automatically. | |
#> | |
[cmdletbinding()] | |
param( | |
[Parameter( | |
Mandatory=$true, | |
Position=0)] | |
$sourceFile, | |
[Parameter( | |
Mandatory=$true, | |
Position=1)] | |
$transformFile | |
) | |
Write-Host $sourceFile | |
Write-Host $transformFile | |
#Apply config transformation | |
function applyConfigTransformation($src, $xdt, $dst) | |
{ | |
Add-Type -Path "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.XmlTransform.dll" | |
try | |
{ | |
Write-Host 'applyConfigTransformation - Called' | |
$doc = New-Object Microsoft.Web.XmlTransform.XmlTransformableDocument | |
$doc.PreserveWhiteSpace = $true | |
Write-Host 'applyConfigTransformation - Load Called' | |
$doc.Load($src) | |
Write-Host 'applyConfigTransformation - Load completed' | |
$trn = New-Object Microsoft.Web.XmlTransform.XmlTransformation($xdt) | |
if ($trn.Apply($doc)) | |
{ | |
Write-Host 'applyConfigTransformation - $trn.Apply called' | |
$doc.Save($dst) | |
Write-Output "Output file: $dst" | |
Write-Host 'applyConfigTransformation - $trn.Apply completed' | |
} | |
else | |
{ | |
throw "Transformation terminated with status False" | |
} | |
} | |
catch | |
{ | |
Write-Output $Error[0].Exception | |
} | |
} | |
applyConfigTransformation $sourceFile $transformFile $sourceFile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment