-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathInvoke-T4.ps1
66 lines (57 loc) · 2.21 KB
/
Invoke-T4.ps1
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
58
59
60
61
62
63
64
65
66
<#
.SYNOPSIS
Runs all the Text Templating Toolkit Transformations in a search path.
#>
function Invoke-T4
{
[CmdletBinding()]
Param(
[string]$RootSearchPath,
[switch] $IncludePackagesFolder
)
Write-Verbose "Requested t4 regeneration for path '$RootSearchPath'"
$searchPath = $RootSearchPath
if (Test-Path $RootSearchPath -PathType Leaf)
{
Write-Verbose "Path was a file, getting directory of file"
$searchPath = Split-Path -Path $RootSearchPath -Parent
Write-Verbose "Resolved folder '$searchPath'"
}
$t4exePath = Join-Path -Path (Get-VsInstallBasePath) -ChildPath "\Common7\IDE\TextTransform.exe"
$tfExePath = Get-TfExePath
if ($IncludePackagesFolder.IsPresent)
{
$ttFiles = @(Get-ChildItem -Path $searchPath -Recurse -File -Include *.tt)
}
else
{
$ttFiles = @(Get-ChildItem -Path $searchPath -Recurse -File -Include *.tt | Where-Object {$_.FullName -notmatch "packages"})
}
Write-Verbose "Found $($ttFiles.Count) tt files"
foreach($ttFile in $ttFiles)
{
Write-Verbose "Calling t4 generation on '$($ttFile.FullName)'"
#<#@ output extension=".txt" #>
$outputExtension = ".cs"
$ttContent = (Get-Content $ttFile.FullName)
foreach ($line in $ttContent)
{
$index = $line.IndexOf("output extension")
if ($index -lt 0) { continue }
$indexOfStartRead = $index + "output extension=`"".Length
$indexOfEndRead = $line.IndexOf("`"", $indexOfStartRead)
$outputExtension = $line.Substring($indexOfStartRead, $indexOfEndRead - $indexOfStartRead)
break
}
$outFile = $ttFile.FullName.Replace(".tt", $outputExtension)
Write-Verbose "Using output file '$outFile'"
if (Get-ItemProperty $outFile -Name IsReadOnly)
{
& $tfExePath vc checkout $outFile
#Set-ItemProperty $outFile -name IsReadOnly -value $false
}
& $t4exePath $($ttFile.FullName) -out $outFile
Write-Verbose "Generation complete"
}
Write-Output "Operation complete"
}