-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransformXml.ps1
More file actions
57 lines (43 loc) · 2.12 KB
/
TransformXml.ps1
File metadata and controls
57 lines (43 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# TransformXml.ps1
#
# Transform any XML file using XDT. This script will download it's dependencies automatically.
#
# Usage:
# . .\TransformXml.ps1
# TransformXml $sourceFile $transformFile $destFile
#
$currentPath = split-path -parent $MyInvocation.MyCommand.Definition
. "$currentPath/GetNuget.ps1"
function TransformXml($sourceFile, $transformFile, $destFile, $toolsDir = ("$env:LOCALAPPDATA\ps-scripts\tools\")){
$nugetDownloadUrl = 'http://nuget.org/nuget.exe'
# slowcheetah.xdt.exe <source file> <transform> <dest file>
$cmdArgs = @((Resolve-Path $sourceFile).ToString(),
(Resolve-Path $transformFile).ToString(),
$destFile)
# get exe and execute transformation
&(_GetTransformXmlExe $toolsDir) $cmdArgs
}
function _GetTransformXmlExe($toolsDir){
$nuget = GetNuget $toolsDir
$xdtExe = (Get-ChildItem -Path $toolsDir -Include 'SlowCheetah.Xdt.exe' -Recurse) | Select-Object -First 1
if(!$xdtExe){
'Downloading xdt since it was not found in the tools folder' | Write-Verbose
# nuget install SlowCheetah.Xdt -Prerelease -OutputDirectory toolsDir\
$cmdArgs = @('install','SlowCheetah.Xdt','-Prerelease','-OutputDirectory',(Resolve-Path $toolsDir).ToString())
# install with nuget
&($nuget) $cmdArgs | Out-Null
$xdtExe = (Get-ChildItem -Path $toolsDir -Include 'SlowCheetah.Xdt.exe' -Recurse) | Select-Object -First 1
# copy the xdt assemlby if the xdt directory is missing it
$xdtDllExpectedPath = (Join-Path $xdtExe.Directory.FullName 'Microsoft.Web.XmlTransform.dll')
if(!(Test-Path $xdtDllExpectedPath)){
# copy the xdt.dll next to the slowcheetah .exe
$xdtDll = (Get-ChildItem -Path $toolsDir -Include 'Microsoft.Web.XmlTransform.dll' -Recurse) | Select-Object -First 1
if(!$xdtDll){ throw 'Microsoft.Web.XmlTransform.dll not found' }
Copy-Item -Path $xdtDll.Fullname -Destination $xdtDllExpectedPath | Out-Null
}
}
if(!$xdtExe){
throw ('SlowCheetah.Xdt not found. Expected location: [{0}]' -f $xdtExe)
}
$xdtExe
}