-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Update-VsixVersion.ps1
47 lines (35 loc) · 1.64 KB
/
Update-VsixVersion.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
[cmdletbinding()]
param (
[Parameter(Position=0, Mandatory=0,ValueFromPipeline=$true)]
[string[]]$manifestFilePath = ".\source.extension.vsixmanifest",
[Parameter(Position=1, Mandatory=$true)]
[Version]$version
)
process {
$version = New-Object Version ([int]$version.Major),([int]$version.Minor),([System.Math]::Max([int]$version.Build, 0)),$env:APPVEYOR_BUILD_NUMBER
$env:VsixVersion = "$version"
foreach($manifestFile in $manifestFilePath)
{
"Setting VSIX version..." | Write-Host -ForegroundColor Cyan -NoNewline
$matches = (Get-ChildItem $manifestFile -Recurse)
$vsixManifest = $matches[$matches.Count - 1] # Get the last one which matches the top most file in the recursive matches
[xml]$vsixXml = Get-Content $vsixManifest
$ns = New-Object System.Xml.XmlNamespaceManager $vsixXml.NameTable
$ns.AddNamespace("ns", $vsixXml.DocumentElement.NamespaceURI) | Out-Null
$attrVersion = ""
if ($vsixXml.SelectSingleNode("//ns:Identity", $ns)){ # VS2012 format
$attrVersion = $vsixXml.SelectSingleNode("//ns:Identity", $ns).Attributes["Version"]
}
elseif ($vsixXml.SelectSingleNode("//ns:Version", $ns)){ # VS2010 format
$attrVersion = $vsixXml.SelectSingleNode("//ns:Version", $ns)
}
$attrVersion.InnerText = $version
$vsixXml.Save($vsixManifest) | Out-Null
$version.ToString() | Write-Host -ForegroundColor Green
# return the values to the pipeline
New-Object PSObject -Property @{
'vsixFilePath' = $vsixManifest
'Version' = $version
}
}
}