对于 Azure 管道中测试的一些依赖项,我需要 Winget 来安装它们。
我尝试了不同的方法。例如,通过使用此脚本,结果如下:
##[error]Test-IsAdmin : The term 'Test-IsAdmin' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\a\1\s\installwinget.ps1:2 char:11
+ if (-not (Test-IsAdmin)) {
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Test-IsAdmin:String) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : CommandNotFoundException
##[error]PowerShell exited with code '1'.
并使用此代码
Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile winget.appinstaller.exe; Start-Process winget.appinstaller.exe
有了这个结果
##[error]Start-Process : This command cannot be run due to the error: The specified executable is not a valid application for
this OS platform..
At D:\a\1\s\sqlserverinstall.ps1:23 char:83
+ ... utFile winget.appinstaller.exe; Start-Process winget.appinstaller.exe
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
我需要一些可以直接在 Azure 管道上运行的东西 (
windows-2022
)。我尝试了其他几种方法。他们都失败了。
如何在 Windows 2022 上的 Azure 管道中安装 Winget?
要在Azure Pipelines中安装Winget,需要参考以下PowerShell脚本:
$progressPreference = 'silentlyContinue'
Write-Information "Downloading WinGet and its dependencies..."
Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile Microsoft.VCLibs.x64.14.00.Desktop.appx
Invoke-WebRequest -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx -OutFile Microsoft.UI.Xaml.2.8.x64.appx
Invoke-WebRequest -Uri https://github.com/microsoft/winget-cli/releases/download/v1.8.1522/cdc44a3f51ec4512b990fb5516afe12d_License1.xml -OutFile cdc44a3f51ec4512b990fb5516afe12d_License1.xml
Add-AppxPackage Microsoft.VCLibs.x64.14.00.Desktop.appx
Add-AppxPackage Microsoft.UI.Xaml.2.8.x64.appx
Add-AppxProvisionedPackage -Online -PackagePath Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle -LicensePath cdc44a3f51ec4512b990fb5516afe12d_License1.xml -Verbose
它将下载/安装 winget 工具并配置所需的许可证。