mirror of
https://github.com/actions/runner-images.git
synced 2025-12-14 13:17:54 +00:00
[Windows] Move Android and VS helpers to dedicated files (#8903)
This commit is contained in:
committed by
GitHub
parent
45a5b970b8
commit
eb0e4ff100
@@ -11,8 +11,9 @@ if (-not $vsixPackagesList) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$vsixPackagesList | ForEach-Object {
|
$vsixPackagesList | ForEach-Object {
|
||||||
# Retrieve cdn endpoint to avoid HTTP error 429 https://github.com/actions/runner-images/issues/3074
|
# Retrieve cdn endpoint to avoid HTTP error 429
|
||||||
$vsixPackage = Get-VsixExtenstionFromMarketplace -ExtensionMarketPlaceName $_
|
# https://github.com/actions/runner-images/issues/3074
|
||||||
|
$vsixPackage = Get-VsixInfoFromMarketplace $_
|
||||||
Write-Host "Installing $vsixPackage"
|
Write-Host "Installing $vsixPackage"
|
||||||
if ($vsixPackage.FileName.EndsWith(".vsix")) {
|
if ($vsixPackage.FileName.EndsWith(".vsix")) {
|
||||||
Install-VSIXFromUrl $vsixPackage.DownloadUri
|
Install-VSIXFromUrl $vsixPackage.DownloadUri
|
||||||
|
|||||||
@@ -24,15 +24,13 @@ function Get-VisualStudioExtensions {
|
|||||||
|
|
||||||
# Additional vsixs
|
# Additional vsixs
|
||||||
$toolset = Get-ToolsetContent
|
$toolset = Get-ToolsetContent
|
||||||
$vsixUrls = $toolset.visualStudio.vsix
|
$vsixPackagesList = $toolset.visualStudio.vsix
|
||||||
if ($vsixUrls)
|
if ($vsixPackagesList) {
|
||||||
{
|
$vsixs = $vsixPackagesList | ForEach-Object {
|
||||||
$vsixs = $vsixUrls | ForEach-Object {
|
$vsixPackage = Get-VsixInfoFromMarketplace $_
|
||||||
$vsix = Get-VsixExtenstionFromMarketplace -ExtensionMarketPlaceName $_
|
$vsixVersion = ($vsPackages | Where-Object { $_.Id -match $vsixPackage.VsixId -and $_.type -eq 'vsix' }).Version
|
||||||
|
|
||||||
$vsixVersion = ($vsPackages | Where-Object {$_.Id -match $vsix.VsixId -and $_.type -eq 'vsix'}).Version
|
|
||||||
@{
|
@{
|
||||||
Package = $vsix.ExtensionName
|
Package = $vsixPackage.ExtensionName
|
||||||
Version = $vsixVersion
|
Version = $vsixVersion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
163
images/windows/scripts/helpers/AndroidHelpers.ps1
Normal file
163
images/windows/scripts/helpers/AndroidHelpers.ps1
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
function Get-AndroidPackages {
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
This function returns a list of available Android packages.
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
The Get-AndroidPackages function checks if a list of packages is already available in a file.
|
||||||
|
If not, it uses the sdkmanager.bat script to generate a list of available packages and saves it to a file.
|
||||||
|
It then returns the content of this file.
|
||||||
|
|
||||||
|
.PARAMETER SDKRootPath
|
||||||
|
The root path of the Android SDK installation.
|
||||||
|
If not specified, the function uses the ANDROID_HOME environment variable.
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Get-AndroidPackages -SDKRootPath "C:\Android\SDK"
|
||||||
|
|
||||||
|
This command returns a list of available Android packages for the specified SDK root path.
|
||||||
|
|
||||||
|
.NOTES
|
||||||
|
This function requires the Android SDK to be installed and the sdkmanager.bat script to be accessible.
|
||||||
|
|
||||||
|
#>
|
||||||
|
Param
|
||||||
|
(
|
||||||
|
[string] $SDKRootPath
|
||||||
|
)
|
||||||
|
|
||||||
|
if (-not $SDKRootPath) {
|
||||||
|
$SDKRootPath = $env:ANDROID_HOME
|
||||||
|
}
|
||||||
|
|
||||||
|
$packagesListFile = "$SDKRootPath\packages-list.txt"
|
||||||
|
$sdkManager = "$SDKRootPath\cmdline-tools\latest\bin\sdkmanager.bat"
|
||||||
|
|
||||||
|
if (-Not (Test-Path -Path $packagesListFile -PathType Leaf)) {
|
||||||
|
(cmd /c "$sdkManager --list --verbose 2>&1") |
|
||||||
|
Where-Object { $_ -Match "^[^\s]" } |
|
||||||
|
Where-Object { $_ -NotMatch "^(Loading |Info: Parsing |---|\[=+|Installed |Available )" } |
|
||||||
|
Where-Object { $_ -NotMatch "^[^;]*$" } |
|
||||||
|
Out-File -FilePath $packagesListFile
|
||||||
|
}
|
||||||
|
|
||||||
|
return Get-Content $packagesListFile
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-AndroidPlatformPackages {
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
This function returns a list of available Android platform packages.
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
The Get-AndroidPlatformPackages function uses the Get-AndroidPackages function to get a list of available packages
|
||||||
|
and filters it to return only platform packages.
|
||||||
|
|
||||||
|
.PARAMETER SDKRootPath
|
||||||
|
The root path of the Android SDK installation.
|
||||||
|
If not specified, the function uses the ANDROID_HOME environment variable.
|
||||||
|
|
||||||
|
.PARAMETER minimumVersion
|
||||||
|
The minimum version of the platform packages to include in the result. Default is 0.
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Get-AndroidPlatformPackages -SDKRootPath "C:\Android\SDK" -minimumVersion 29
|
||||||
|
|
||||||
|
This command returns a list of available Android platform packages for the specified SDK root path with a minimum version of 29.
|
||||||
|
|
||||||
|
.NOTES
|
||||||
|
This function requires the Android SDK to be installed and the sdkmanager.bat script to be accessible.
|
||||||
|
|
||||||
|
#>
|
||||||
|
Param
|
||||||
|
(
|
||||||
|
[string] $SDKRootPath,
|
||||||
|
[Alias("minVersion")]
|
||||||
|
[int] $minimumVersion = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
if (-not $SDKRootPath) {
|
||||||
|
$SDKRootPath = $env:ANDROID_HOME
|
||||||
|
}
|
||||||
|
|
||||||
|
return (Get-AndroidPackages -SDKRootPath $SDKRootPath) `
|
||||||
|
| Where-Object { "$_".StartsWith("platforms;") } `
|
||||||
|
| Where-Object { ($_.Split("-")[1] -as [int]) -ge $minimumVersion } `
|
||||||
|
| Sort-Object -Unique
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-AndroidBuildToolPackages {
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
This function returns a list of available Android build tool packages.
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
The Get-AndroidBuildToolPackages function uses the Get-AndroidPackages function to get a list of available packages
|
||||||
|
and filters it to return only build tool packages.
|
||||||
|
|
||||||
|
.PARAMETER SDKRootPath
|
||||||
|
The root path of the Android SDK installation.
|
||||||
|
If not specified, the function uses the ANDROID_HOME environment variable.
|
||||||
|
|
||||||
|
.PARAMETER minimumVersion
|
||||||
|
The minimum version of the build tool packages to include in the result. Default is 0.0.0.
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Get-AndroidBuildToolPackages -SDKRootPath "C:\Android\SDK" -minimumVersion "30.0.2"
|
||||||
|
|
||||||
|
This command returns a list of available Android build tool packages for the specified SDK root path with a minimum version of 30.0.2.
|
||||||
|
|
||||||
|
.NOTES
|
||||||
|
This function requires the Android SDK to be installed and the sdkmanager.bat script to be accessible.
|
||||||
|
|
||||||
|
#>
|
||||||
|
Param
|
||||||
|
(
|
||||||
|
[string] $SDKRootPath,
|
||||||
|
[Alias("minVersion")]
|
||||||
|
[version] $minimumVersion = "0.0.0"
|
||||||
|
)
|
||||||
|
|
||||||
|
if (-not $SDKRootPath) {
|
||||||
|
$SDKRootPath = $env:ANDROID_HOME
|
||||||
|
}
|
||||||
|
|
||||||
|
return (Get-AndroidPackages -SDKRootPath $SDKRootPath) `
|
||||||
|
| Where-Object { "$_".StartsWith("build-tools;") } `
|
||||||
|
| Where-Object { ($_.Split(";")[1] -as [version]) -ge $minimumVersion } `
|
||||||
|
| Sort-Object -Unique
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-AndroidInstalledPackages {
|
||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Retrieves a list of installed Android packages.
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
This function retrieves a list of installed Android packages using the specified SDK root path.
|
||||||
|
|
||||||
|
.PARAMETER SDKRootPath
|
||||||
|
The root path of the Android SDK.
|
||||||
|
If not specified, the function uses the ANDROID_HOME environment variable.
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Get-AndroidInstalledPackages -SDKRootPath "C:\Android\SDK"
|
||||||
|
Retrieves a list of installed Android packages using the specified SDK root path.
|
||||||
|
|
||||||
|
.NOTES
|
||||||
|
This function requires the Android SDK to be installed and the SDK root path to be provided.
|
||||||
|
#>
|
||||||
|
|
||||||
|
Param
|
||||||
|
(
|
||||||
|
[string] $SDKRootPath
|
||||||
|
)
|
||||||
|
|
||||||
|
if (-not $SDKRootPath) {
|
||||||
|
$SDKRootPath = $env:ANDROID_HOME
|
||||||
|
}
|
||||||
|
|
||||||
|
$sdkManager = "$SDKRootPath\cmdline-tools\latest\bin\sdkmanager.bat"
|
||||||
|
|
||||||
|
return (cmd /c "$sdkManager --list_installed 2>&1") -notmatch "Warning"
|
||||||
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
[CmdletBinding()]
|
[CmdletBinding()]
|
||||||
param()
|
param()
|
||||||
|
|
||||||
. $PSScriptRoot\PathHelpers.ps1
|
. $PSScriptRoot\AndroidHelpers.ps1
|
||||||
. $PSScriptRoot\InstallHelpers.ps1
|
|
||||||
. $PSScriptRoot\ChocoHelpers.ps1
|
. $PSScriptRoot\ChocoHelpers.ps1
|
||||||
|
. $PSScriptRoot\InstallHelpers.ps1
|
||||||
|
. $PSScriptRoot\PathHelpers.ps1
|
||||||
. $PSScriptRoot\VisualStudioHelpers.ps1
|
. $PSScriptRoot\VisualStudioHelpers.ps1
|
||||||
|
|
||||||
Export-ModuleMember -Function @(
|
Export-ModuleMember -Function @(
|
||||||
@@ -17,7 +18,7 @@ Export-ModuleMember -Function @(
|
|||||||
'Get-TCToolVersionPath'
|
'Get-TCToolVersionPath'
|
||||||
'Get-TCToolPath'
|
'Get-TCToolPath'
|
||||||
'Invoke-DownloadWithRetry'
|
'Invoke-DownloadWithRetry'
|
||||||
'Get-VsixExtenstionFromMarketplace'
|
'Get-VsixInfoFromMarketplace'
|
||||||
'Install-VSIXFromFile'
|
'Install-VSIXFromFile'
|
||||||
'Install-VSIXFromUrl'
|
'Install-VSIXFromUrl'
|
||||||
'Get-VSExtensionVersion'
|
'Get-VSExtensionVersion'
|
||||||
@@ -25,7 +26,6 @@ Export-ModuleMember -Function @(
|
|||||||
'Test-IsWin22'
|
'Test-IsWin22'
|
||||||
'Test-IsWin19'
|
'Test-IsWin19'
|
||||||
'Install-ChocoPackage'
|
'Install-ChocoPackage'
|
||||||
'Send-RequestToCocolateyPackages'
|
|
||||||
'Resolve-ChocoPackageVersion'
|
'Resolve-ChocoPackageVersion'
|
||||||
'Resolve-GithubReleaseAssetUrl'
|
'Resolve-GithubReleaseAssetUrl'
|
||||||
'Expand-7ZipArchive'
|
'Expand-7ZipArchive'
|
||||||
|
|||||||
@@ -179,136 +179,6 @@ function Invoke-DownloadWithRetry {
|
|||||||
return $Path
|
return $Path
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-VsixExtenstionFromMarketplace {
|
|
||||||
Param
|
|
||||||
(
|
|
||||||
[string] $ExtensionMarketPlaceName,
|
|
||||||
[string] $MarketplaceUri = "https://marketplace.visualstudio.com/items?itemName="
|
|
||||||
)
|
|
||||||
|
|
||||||
# Invoke-WebRequest doesn't support retry in PowerShell 5.1
|
|
||||||
$request = Invoke-ScriptBlockWithRetry -RetryCount 20 -RetryIntervalSeconds 30 -Command {
|
|
||||||
Invoke-WebRequest -Uri "${MarketplaceUri}${ExtensionMarketPlaceName}" -UseBasicParsing
|
|
||||||
}
|
|
||||||
$request -match 'UniqueIdentifierValue":"(?<extensionname>[^"]*)' | Out-Null
|
|
||||||
$extensionName = $Matches.extensionname
|
|
||||||
$request -match 'VsixId":"(?<vsixid>[^"]*)' | Out-Null
|
|
||||||
$vsixId = $Matches.vsixid
|
|
||||||
$request -match 'AssetUri":"(?<uri>[^"]*)' | Out-Null
|
|
||||||
$assetUri = $Matches.uri
|
|
||||||
$request -match 'Microsoft\.VisualStudio\.Services\.Payload\.FileName":"(?<filename>[^"]*)' | Out-Null
|
|
||||||
$fileName = $Matches.filename
|
|
||||||
$downloadUri = $assetUri + "/" + $fileName
|
|
||||||
# ProBITools.MicrosoftReportProjectsforVisualStudio2022 has different URL https://github.com/actions/runner-images/issues/5340
|
|
||||||
switch ($ExtensionMarketPlaceName) {
|
|
||||||
"ProBITools.MicrosoftReportProjectsforVisualStudio2022" {
|
|
||||||
$fileName = "Microsoft.DataTools.ReportingServices.vsix"
|
|
||||||
$downloadUri = "https://download.microsoft.com/download/b/b/5/bb57be7e-ae72-4fc0-b528-d0ec224997bd/Microsoft.DataTools.ReportingServices.vsix"
|
|
||||||
}
|
|
||||||
"ProBITools.MicrosoftAnalysisServicesModelingProjects2022" {
|
|
||||||
$fileName = "Microsoft.DataTools.AnalysisServices.vsix"
|
|
||||||
$downloadUri = "https://download.microsoft.com/download/c/8/9/c896a7f2-d0fd-45ac-90e6-ff61f67523cb/Microsoft.DataTools.AnalysisServices.vsix"
|
|
||||||
}
|
|
||||||
# Starting from version 4.1 SqlServerIntegrationServicesProjects extension is distributed as exe file
|
|
||||||
"SSIS.SqlServerIntegrationServicesProjects" {
|
|
||||||
$fileName = "Microsoft.DataTools.IntegrationServices.exe"
|
|
||||||
$downloadUri = $assetUri + "/" + $fileName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return [PSCustomObject] @{
|
|
||||||
"ExtensionName" = $extensionName
|
|
||||||
"VsixId" = $vsixId
|
|
||||||
"FileName" = $fileName
|
|
||||||
"DownloadUri" = $downloadUri
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function Install-VSIXFromFile {
|
|
||||||
Param
|
|
||||||
(
|
|
||||||
[Parameter(Mandatory = $true)]
|
|
||||||
[string] $FilePath,
|
|
||||||
[int] $Retries = 20
|
|
||||||
)
|
|
||||||
|
|
||||||
Write-Host "Installing VSIX from $FilePath..."
|
|
||||||
while ($True) {
|
|
||||||
$installerPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service\VSIXInstaller.exe"
|
|
||||||
try {
|
|
||||||
$process = Start-Process `
|
|
||||||
-FilePath $installerPath `
|
|
||||||
-ArgumentList @('/quiet', "`"$FilePath`"") `
|
|
||||||
-Wait -PassThru
|
|
||||||
} catch {
|
|
||||||
Write-Host "Failed to start VSIXInstaller.exe with error:"
|
|
||||||
$_
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
$exitCode = $process.ExitCode
|
|
||||||
|
|
||||||
if ($exitCode -eq 0) {
|
|
||||||
Write-Host "VSIX installed successfully."
|
|
||||||
break
|
|
||||||
} elseif ($exitCode -eq 1001) {
|
|
||||||
Write-Host "VSIX is already installed."
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "VSIX installation failed with exit code $exitCode."
|
|
||||||
|
|
||||||
$Retries--
|
|
||||||
if ($Retries -eq 0) {
|
|
||||||
Write-Host "VSIX installation failed after $Retries retries."
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
Write-Host "Waiting 10 seconds before retrying. Retries left: $Retries"
|
|
||||||
Start-Sleep -Seconds 10
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function Install-VSIXFromUrl {
|
|
||||||
Param
|
|
||||||
(
|
|
||||||
[Parameter(Mandatory = $true)]
|
|
||||||
[string] $Url,
|
|
||||||
[int] $Retries = 20
|
|
||||||
)
|
|
||||||
|
|
||||||
$filePath = Invoke-DownloadWithRetry $Url
|
|
||||||
Install-VSIXFromFile -FilePath $filePath -Retries $Retries
|
|
||||||
Remove-Item -Force -Confirm:$false $filePath
|
|
||||||
}
|
|
||||||
|
|
||||||
function Get-VSExtensionVersion {
|
|
||||||
Param
|
|
||||||
(
|
|
||||||
[Parameter(Mandatory = $true)]
|
|
||||||
[string] $packageName
|
|
||||||
)
|
|
||||||
|
|
||||||
$instanceFolders = Get-ChildItem -Path "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances"
|
|
||||||
if ($instanceFolders -is [array]) {
|
|
||||||
Write-Host ($instanceFolders | Out-String)
|
|
||||||
Write-Host ($instanceFolders | Get-ChildItem | Out-String)
|
|
||||||
Write-Host "More than one instance installed"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
$stateContent = Get-Content -Path (Join-Path $instanceFolders.FullName '\state.packages.json')
|
|
||||||
$state = $stateContent | ConvertFrom-Json
|
|
||||||
$packageVersion = ($state.packages | Where-Object { $_.id -eq $packageName }).version
|
|
||||||
|
|
||||||
if (-not $packageVersion) {
|
|
||||||
Write-Host "Installed package $packageName for Visual Studio was not found"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
return $packageVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
function Get-ToolsetContent {
|
function Get-ToolsetContent {
|
||||||
$toolsetPath = Join-Path "C:\\image" "toolset.json"
|
$toolsetPath = Join-Path "C:\\image" "toolset.json"
|
||||||
$toolsetJson = Get-Content -Path $toolsetPath -Raw
|
$toolsetJson = Get-Content -Path $toolsetPath -Raw
|
||||||
@@ -428,170 +298,6 @@ function Expand-7ZipArchive {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-AndroidPackages {
|
|
||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
This function returns a list of available Android packages.
|
|
||||||
|
|
||||||
.DESCRIPTION
|
|
||||||
The Get-AndroidPackages function checks if a list of packages is already available in a file.
|
|
||||||
If not, it uses the sdkmanager.bat script to generate a list of available packages and saves it to a file.
|
|
||||||
It then returns the content of this file.
|
|
||||||
|
|
||||||
.PARAMETER SDKRootPath
|
|
||||||
The root path of the Android SDK installation.
|
|
||||||
If not specified, the function uses the ANDROID_HOME environment variable.
|
|
||||||
|
|
||||||
.EXAMPLE
|
|
||||||
Get-AndroidPackages -SDKRootPath "C:\Android\SDK"
|
|
||||||
|
|
||||||
This command returns a list of available Android packages for the specified SDK root path.
|
|
||||||
|
|
||||||
.NOTES
|
|
||||||
This function requires the Android SDK to be installed and the sdkmanager.bat script to be accessible.
|
|
||||||
|
|
||||||
#>
|
|
||||||
Param
|
|
||||||
(
|
|
||||||
[string] $SDKRootPath
|
|
||||||
)
|
|
||||||
|
|
||||||
if (-not $SDKRootPath) {
|
|
||||||
$SDKRootPath = $env:ANDROID_HOME
|
|
||||||
}
|
|
||||||
|
|
||||||
$packagesListFile = "$SDKRootPath\packages-list.txt"
|
|
||||||
$sdkManager = "$SDKRootPath\cmdline-tools\latest\bin\sdkmanager.bat"
|
|
||||||
|
|
||||||
if (-Not (Test-Path -Path $packagesListFile -PathType Leaf)) {
|
|
||||||
(cmd /c "$sdkManager --list --verbose 2>&1") |
|
|
||||||
Where-Object { $_ -Match "^[^\s]" } |
|
|
||||||
Where-Object { $_ -NotMatch "^(Loading |Info: Parsing |---|\[=+|Installed |Available )" } |
|
|
||||||
Where-Object { $_ -NotMatch "^[^;]*$" } |
|
|
||||||
Out-File -FilePath $packagesListFile
|
|
||||||
}
|
|
||||||
|
|
||||||
return Get-Content $packagesListFile
|
|
||||||
}
|
|
||||||
|
|
||||||
function Get-AndroidPlatformPackages {
|
|
||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
This function returns a list of available Android platform packages.
|
|
||||||
|
|
||||||
.DESCRIPTION
|
|
||||||
The Get-AndroidPlatformPackages function uses the Get-AndroidPackages function to get a list of available packages
|
|
||||||
and filters it to return only platform packages.
|
|
||||||
|
|
||||||
.PARAMETER SDKRootPath
|
|
||||||
The root path of the Android SDK installation.
|
|
||||||
If not specified, the function uses the ANDROID_HOME environment variable.
|
|
||||||
|
|
||||||
.PARAMETER minimumVersion
|
|
||||||
The minimum version of the platform packages to include in the result. Default is 0.
|
|
||||||
|
|
||||||
.EXAMPLE
|
|
||||||
Get-AndroidPlatformPackages -SDKRootPath "C:\Android\SDK" -minimumVersion 29
|
|
||||||
|
|
||||||
This command returns a list of available Android platform packages for the specified SDK root path with a minimum version of 29.
|
|
||||||
|
|
||||||
.NOTES
|
|
||||||
This function requires the Android SDK to be installed and the sdkmanager.bat script to be accessible.
|
|
||||||
|
|
||||||
#>
|
|
||||||
Param
|
|
||||||
(
|
|
||||||
[string] $SDKRootPath,
|
|
||||||
[Alias("minVersion")]
|
|
||||||
[int] $minimumVersion = 0
|
|
||||||
)
|
|
||||||
|
|
||||||
if (-not $SDKRootPath) {
|
|
||||||
$SDKRootPath = $env:ANDROID_HOME
|
|
||||||
}
|
|
||||||
|
|
||||||
return (Get-AndroidPackages -SDKRootPath $SDKRootPath) `
|
|
||||||
| Where-Object { "$_".StartsWith("platforms;") } `
|
|
||||||
| Where-Object { ($_.Split("-")[1] -as [int]) -ge $minimumVersion } `
|
|
||||||
| Sort-Object -Unique
|
|
||||||
}
|
|
||||||
|
|
||||||
function Get-AndroidBuildToolPackages {
|
|
||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
This function returns a list of available Android build tool packages.
|
|
||||||
|
|
||||||
.DESCRIPTION
|
|
||||||
The Get-AndroidBuildToolPackages function uses the Get-AndroidPackages function to get a list of available packages
|
|
||||||
and filters it to return only build tool packages.
|
|
||||||
|
|
||||||
.PARAMETER SDKRootPath
|
|
||||||
The root path of the Android SDK installation.
|
|
||||||
If not specified, the function uses the ANDROID_HOME environment variable.
|
|
||||||
|
|
||||||
.PARAMETER minimumVersion
|
|
||||||
The minimum version of the build tool packages to include in the result. Default is 0.0.0.
|
|
||||||
|
|
||||||
.EXAMPLE
|
|
||||||
Get-AndroidBuildToolPackages -SDKRootPath "C:\Android\SDK" -minimumVersion "30.0.2"
|
|
||||||
|
|
||||||
This command returns a list of available Android build tool packages for the specified SDK root path with a minimum version of 30.0.2.
|
|
||||||
|
|
||||||
.NOTES
|
|
||||||
This function requires the Android SDK to be installed and the sdkmanager.bat script to be accessible.
|
|
||||||
|
|
||||||
#>
|
|
||||||
Param
|
|
||||||
(
|
|
||||||
[string] $SDKRootPath,
|
|
||||||
[Alias("minVersion")]
|
|
||||||
[version] $minimumVersion = "0.0.0"
|
|
||||||
)
|
|
||||||
|
|
||||||
if (-not $SDKRootPath) {
|
|
||||||
$SDKRootPath = $env:ANDROID_HOME
|
|
||||||
}
|
|
||||||
|
|
||||||
return (Get-AndroidPackages -SDKRootPath $SDKRootPath) `
|
|
||||||
| Where-Object { "$_".StartsWith("build-tools;") } `
|
|
||||||
| Where-Object { ($_.Split(";")[1] -as [version]) -ge $minimumVersion } `
|
|
||||||
| Sort-Object -Unique
|
|
||||||
}
|
|
||||||
|
|
||||||
function Get-AndroidInstalledPackages {
|
|
||||||
<#
|
|
||||||
.SYNOPSIS
|
|
||||||
Retrieves a list of installed Android packages.
|
|
||||||
|
|
||||||
.DESCRIPTION
|
|
||||||
This function retrieves a list of installed Android packages using the specified SDK root path.
|
|
||||||
|
|
||||||
.PARAMETER SDKRootPath
|
|
||||||
The root path of the Android SDK.
|
|
||||||
If not specified, the function uses the ANDROID_HOME environment variable.
|
|
||||||
|
|
||||||
.EXAMPLE
|
|
||||||
Get-AndroidInstalledPackages -SDKRootPath "C:\Android\SDK"
|
|
||||||
Retrieves a list of installed Android packages using the specified SDK root path.
|
|
||||||
|
|
||||||
.NOTES
|
|
||||||
This function requires the Android SDK to be installed and the SDK root path to be provided.
|
|
||||||
#>
|
|
||||||
|
|
||||||
Param
|
|
||||||
(
|
|
||||||
[string] $SDKRootPath
|
|
||||||
)
|
|
||||||
|
|
||||||
if (-not $SDKRootPath) {
|
|
||||||
$SDKRootPath = $env:ANDROID_HOME
|
|
||||||
}
|
|
||||||
|
|
||||||
$sdkManager = "$SDKRootPath\cmdline-tools\latest\bin\sdkmanager.bat"
|
|
||||||
|
|
||||||
return (cmd /c "$sdkManager --list_installed 2>&1") -notmatch "Warning"
|
|
||||||
}
|
|
||||||
|
|
||||||
function Get-WindowsUpdateStates {
|
function Get-WindowsUpdateStates {
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
|
|||||||
@@ -116,11 +116,6 @@ Function Install-VisualStudio {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function Get-VsCatalogJsonPath {
|
|
||||||
$instanceFolder = Get-Item "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances\*" | Select-Object -First 1
|
|
||||||
return Join-Path $instanceFolder.FullName "catalog.json"
|
|
||||||
}
|
|
||||||
|
|
||||||
function Get-VisualStudioInstance {
|
function Get-VisualStudioInstance {
|
||||||
# Use -Prerelease and -All flags to make sure that Preview versions of VS are found correctly
|
# Use -Prerelease and -All flags to make sure that Preview versions of VS are found correctly
|
||||||
$vsInstance = Get-VSSetupInstance -Prerelease -All | Where-Object { $_.DisplayName -match "Visual Studio" } | Select-Object -First 1
|
$vsInstance = Get-VSSetupInstance -Prerelease -All | Where-Object { $_.DisplayName -match "Visual Studio" } | Select-Object -First 1
|
||||||
@@ -132,3 +127,142 @@ function Get-VisualStudioComponents {
|
|||||||
Sort-Object Id, Version | Select-Object @{n = 'Package'; e = { $_.Id } }, Version |
|
Sort-Object Id, Version | Select-Object @{n = 'Package'; e = { $_.Id } }, Version |
|
||||||
Where-Object { $_.Package -notmatch "[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}" }
|
Where-Object { $_.Package -notmatch "[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Get-VsixInfoFromMarketplace {
|
||||||
|
Param
|
||||||
|
(
|
||||||
|
[Parameter(Mandatory)]
|
||||||
|
[Alias("ExtensionMarketPlaceName")]
|
||||||
|
[string] $Name,
|
||||||
|
[string] $MarketplaceUri = "https://marketplace.visualstudio.com/items?itemName="
|
||||||
|
)
|
||||||
|
|
||||||
|
# Invoke-WebRequest doesn't support retry in PowerShell 5.1
|
||||||
|
$webResponse = Invoke-ScriptBlockWithRetry -RetryCount 20 -RetryIntervalSeconds 30 -Command {
|
||||||
|
Invoke-WebRequest -Uri "${MarketplaceUri}${Name}" -UseBasicParsing
|
||||||
|
}
|
||||||
|
|
||||||
|
$webResponse -match 'UniqueIdentifierValue":"(?<extensionname>[^"]*)' | Out-Null
|
||||||
|
$extensionName = $Matches.extensionname
|
||||||
|
|
||||||
|
$webResponse -match 'VsixId":"(?<vsixid>[^"]*)' | Out-Null
|
||||||
|
$vsixId = $Matches.vsixid
|
||||||
|
|
||||||
|
$webResponse -match 'AssetUri":"(?<uri>[^"]*)' | Out-Null
|
||||||
|
$assetUri = $Matches.uri
|
||||||
|
|
||||||
|
$webResponse -match 'Microsoft\.VisualStudio\.Services\.Payload\.FileName":"(?<filename>[^"]*)' | Out-Null
|
||||||
|
$fileName = $Matches.filename
|
||||||
|
|
||||||
|
switch ($Name) {
|
||||||
|
# ProBITools.MicrosoftReportProjectsforVisualStudio2022 has different URL
|
||||||
|
# https://github.com/actions/runner-images/issues/5340
|
||||||
|
"ProBITools.MicrosoftReportProjectsforVisualStudio2022" {
|
||||||
|
$assetUri = "https://download.microsoft.com/download/b/b/5/bb57be7e-ae72-4fc0-b528-d0ec224997bd"
|
||||||
|
$fileName = "Microsoft.DataTools.ReportingServices.vsix"
|
||||||
|
}
|
||||||
|
"ProBITools.MicrosoftAnalysisServicesModelingProjects2022" {
|
||||||
|
$assetUri = "https://download.microsoft.com/download/c/8/9/c896a7f2-d0fd-45ac-90e6-ff61f67523cb"
|
||||||
|
$fileName = "Microsoft.DataTools.AnalysisServices.vsix"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Starting from version 4.1 SqlServerIntegrationServicesProjects extension is distributed as exe file
|
||||||
|
"SSIS.SqlServerIntegrationServicesProjects" {
|
||||||
|
$fileName = "Microsoft.DataTools.IntegrationServices.exe"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$downloadUri = $assetUri + "/" + $fileName
|
||||||
|
|
||||||
|
return [PSCustomObject] @{
|
||||||
|
"ExtensionName" = $extensionName
|
||||||
|
"VsixId" = $vsixId
|
||||||
|
"FileName" = $fileName
|
||||||
|
"DownloadUri" = $downloadUri
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Install-VSIXFromFile {
|
||||||
|
Param
|
||||||
|
(
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string] $FilePath,
|
||||||
|
[int] $Retries = 20
|
||||||
|
)
|
||||||
|
|
||||||
|
Write-Host "Installing VSIX from $FilePath..."
|
||||||
|
while ($True) {
|
||||||
|
$installerPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service\VSIXInstaller.exe"
|
||||||
|
try {
|
||||||
|
$process = Start-Process `
|
||||||
|
-FilePath $installerPath `
|
||||||
|
-ArgumentList @('/quiet', "`"$FilePath`"") `
|
||||||
|
-Wait -PassThru
|
||||||
|
} catch {
|
||||||
|
Write-Host "Failed to start VSIXInstaller.exe with error:"
|
||||||
|
$_
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$exitCode = $process.ExitCode
|
||||||
|
|
||||||
|
if ($exitCode -eq 0) {
|
||||||
|
Write-Host "VSIX installed successfully."
|
||||||
|
break
|
||||||
|
} elseif ($exitCode -eq 1001) {
|
||||||
|
Write-Host "VSIX is already installed."
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "VSIX installation failed with exit code $exitCode."
|
||||||
|
|
||||||
|
$Retries--
|
||||||
|
if ($Retries -eq 0) {
|
||||||
|
Write-Host "VSIX installation failed after $Retries retries."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Waiting 10 seconds before retrying. Retries left: $Retries"
|
||||||
|
Start-Sleep -Seconds 10
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Install-VSIXFromUrl {
|
||||||
|
Param
|
||||||
|
(
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string] $Url,
|
||||||
|
[int] $Retries = 20
|
||||||
|
)
|
||||||
|
|
||||||
|
$filePath = Invoke-DownloadWithRetry $Url
|
||||||
|
Install-VSIXFromFile -FilePath $filePath -Retries $Retries
|
||||||
|
Remove-Item -Force -Confirm:$false $filePath
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-VSExtensionVersion {
|
||||||
|
Param
|
||||||
|
(
|
||||||
|
[Parameter(Mandatory = $true)]
|
||||||
|
[string] $packageName
|
||||||
|
)
|
||||||
|
|
||||||
|
$instanceFolders = Get-ChildItem -Path "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances"
|
||||||
|
if ($instanceFolders -is [array]) {
|
||||||
|
Write-Host ($instanceFolders | Out-String)
|
||||||
|
Write-Host ($instanceFolders | Get-ChildItem | Out-String)
|
||||||
|
Write-Host "More than one instance installed"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$stateContent = Get-Content -Path (Join-Path $instanceFolders.FullName '\state.packages.json')
|
||||||
|
$state = $stateContent | ConvertFrom-Json
|
||||||
|
$packageVersion = ($state.packages | Where-Object { $_.id -eq $packageName }).version
|
||||||
|
|
||||||
|
if (-not $packageVersion) {
|
||||||
|
Write-Host "Installed package $packageName for Visual Studio was not found"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return $packageVersion
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
Describe "Visual Studio" {
|
Describe "Visual Studio" {
|
||||||
Context "Basic" {
|
Context "Basic" {
|
||||||
It "Catalog.json" {
|
It "Catalog.json" {
|
||||||
Get-VsCatalogJsonPath | Should -Exist
|
$instanceFolder = Get-Item "C:\ProgramData\Microsoft\VisualStudio\Packages\_Instances\*" | Select-Object -First 1
|
||||||
|
Join-Path $instanceFolder.FullName "catalog.json" | Should -Exist
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Devenv.exe" {
|
It "Devenv.exe" {
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
Describe "Vsix" {
|
Describe "Vsix" {
|
||||||
$toolset = Get-ToolsetContent
|
$toolset = Get-ToolsetContent
|
||||||
$requiredVsixs = $toolset.visualStudio.vsix
|
$requiredVsixPackages = $toolset.visualStudio.vsix
|
||||||
|
|
||||||
$allPackages = (Get-VisualStudioInstance).Packages
|
$allPackages = (Get-VisualStudioInstance).Packages
|
||||||
$testCases = $requiredVsixs | ForEach-Object {
|
$testCases = $requiredVsixPackages | ForEach-Object {
|
||||||
$vsix = Get-VsixExtenstionFromMarketplace -ExtensionMarketPlaceName $_
|
$vsixPackage = Get-VsixInfoFromMarketplace $_
|
||||||
@{
|
@{
|
||||||
VsixName = $vsix.ExtensionName
|
VsixName = $vsixPackage.ExtensionName
|
||||||
VsixId = $vsix.VsixId
|
VsixId = $vsixPackage.VsixId
|
||||||
AllPackages = $allPackages
|
AllPackages = $allPackages
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user