-
Notifications
You must be signed in to change notification settings - Fork 205
/
add-templateid.ps1
39 lines (33 loc) · 1.28 KB
/
add-templateid.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
[cmdletbinding()]
param(
$rootDir
)
function InternalGet-ScriptDirectory{
split-path (((Get-Variable MyInvocation -Scope 1).Value).MyCommand.Path)
}
$scriptDir = ((InternalGet-ScriptDirectory) + "\")
if([string]::IsNullOrEmpty($rootDir)){
$rootDir = $scriptDir
}
if(-not (Test-Path $rootDir)){
throw ('rootDir not found at [{0}]' -f $rootDir)
}
Get-ChildItem $rootDir -Include *.vstemplate,_project.vstemplate.xml -Recurse -File | ForEach-Object {
$templatepath = $_
'Inspecting [{0}] for TemplateID' -f $templatepath | Write-Verbose
try{
[xml]$template = Get-Content $_
# see if the file has a TemplateId parameter, if so leave it alone
if(-not $template.VSTemplate.TemplateData.TemplateID){
'Adding TemplateId to [{0}]' -f $templatepath | Write-Verbose
$idelement = $template.CreateElement('TemplateID','http://schemas.microsoft.com/developer/vstemplate/2005')
$idelement.InnerText = ([guid]::NewGuid())
$template.VSTemplate.TemplateData.AppendChild($idelement) | Out-Null
$template.Save($templatepath) | Out-Null
}
}
catch{
'Unable to read/write to the file [{0}]. Error: {1}' -f $templatepath, $_.Exception | Write-Error
throw $_.Exception
}
}