-
Notifications
You must be signed in to change notification settings - Fork 0
/
vsix.psm1
74 lines (59 loc) · 2.04 KB
/
vsix.psm1
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
67
68
69
70
71
72
73
74
$CsVersionFile = "**\Package.cs"
$CsVersionPattern = 'VERSION = "([\d\\.]+)"'
$CsVersionFormat = 'VERSION = "{0}"'
$VsixManifests = "**\source.extension.vsixmanifest"
function UpdateVersion {
[cmdletbinding()]
param(
[Parameter(Mandatory=$true)]
[string] $Version
)
Write-Host "Update vsix version to :" $Version -ForegroundColor Green
UpdateVersionFile $Version
UpdateManifestVersion $Version
}
function UpdateVersionFile {
param(
[string] $Version
)
$file = Resolve-Path $CsVersionFile
(Get-Content $file) | ForEach-Object {
if ($_ -cmatch $CsVersionPattern){
$_ -creplace $CsVersionPattern, ($CsVersionFormat -f $Version)
}
else {
$_
}
} | Set-Content $file -Encoding UTF8
Write-Host "Version updated:" $file -ForegroundColor Green
}
function UpdateManifestVersion {
param(
[string] $Version
)
$files = Resolve-Path $VsixManifests
$files | ForEach-Object {
[xml]$content = Get-Content $_
$content.PackageManifest.Metadata.Identity.Version = $Version
$content.Save($_)
Write-Host "Version updated:" $_ -ForegroundColor Green
}
}
function PublishVsix {
[cmdletbinding()]
param(
[string] $PAT,
[string] $vsix,
[string] $manifest
)
$vsix = Resolve-Path $vsix
$manifest = Resolve-Path $manifest
$installation = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -format json | ConvertFrom-Json
$path = $installation.installationPath
$vsixPublisher = Join-Path -Path $path -ChildPath "VSSDK\VisualStudioIntegration\Tools\Bin\VsixPublisher.exe" -Resolve
Write-Host "VsixPublisher:" $vsixPublisher -ForegroundColor Green
Write-Host "Manifest:" $manifest -ForegroundColor Green
Write-Host "Vsix:" $vsix -ForegroundColor Green
& $vsixPublisher publish -payload "$vsix" -publishManifest "$manifest" -personalAccessToken $PAT
}
Export-ModuleMember -Function UpdateVersion, PublishVsix