Azure Artifacts 无法与 powershell 存储库一起使用

标签 azure powershell azure-devops devops azure-artifacts

我对 Azure Artifacts 和与其共享私有(private) powershell 存储库有一个有趣的问题。

我遵循了微软官方文档中提供的指导:MS doc

我成功打包模块并将其发布到 azure 工件。但是当我尝试使用 powershell 连接到 feed 时,我遇到了一些问题:

Register-PSRepository 和 Register-PackageSource 工作正常。但 Find-Module 给了我第一个错误:

Register-PSRepository -Name "PowershellAzureDevopsServices" -SourceLocation "https://pkgs.dev.azure.com/myorg/myprojectid/_packaging/myfeed/nuget/v2" -PublishLocation "https://pkgs.dev.azure.com/myorg/myprojectid/_packaging/myfeed/nuget/v2" -InstallationPolicy Trusted -Credential $credsAzureDevopsServices
        
Register-PackageSource -Name "PowershellAzureDevopsServices" -Location "https://pkgs.dev.azure.com/myorg/myprojectid/_packaging/myfeed/nuget/v2" -ProviderName NuGet -Trusted -SkipValidate -Credential $credsAzureDevopsServices
        
Find-Module -Repository PowershellAzureDevopsServices

WARNUNG: Cannot access
'https://pkgs.dev.azure.com/myorg/myprojectid/_packaging/myfeed/nuget/v2'. Are you
missing 'Credential' parameter in the cmdlet?
WARNUNG: Query Url

然后我将凭证参数放入 Find-Module,它向我显示了预期的模块:

Find-Module -Repository PowershellAzureDevopsServices -Credential $credsAzureDevopsServices

Version    Name                                Repository           Description
-------    ----                                ----------           -----------
0.0.7      Example.Module                      PowershellAzureDe... Package description
1.0.0      Get-Hello                           PowershellAzureDe... Package description

但是当我尝试安装找到的模块时,出现下一个错误。这个错误我无法解决:

Find-Module -Repository PowershellAzureDevopsServices -Credential $credsAzureDevopsServices | Install-Module -Credential $credsAzureDevopsServices -Scope CurrentUser
PackageManagement\Install-Package : Unable to find dependent module(s) (SampleDependency)
In C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1912 Zeichen:34
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
    + FullyQualifiedErrorId : UnableToFindDependencyPackage,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPac
   kage

PackageManagement\Install-Package : Unable to find dependent module(s) (SampleDependency)
In C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1912 Zeichen:34
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (SampleDependency:String) [Install-Package], Exception
    + FullyQualifiedErrorId : UnableToFindDependencyPackage,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPac
   kage

到目前为止我也尝试过:

  • 尝试使用 nugetv3 网址而不是 v2 https://pkgs.dev.azure.com/myorg/myprojectid/_packaging/myfeed/nuget/v3/index.json
  • 我还检查了包源和 PSRepository。在这里我发现有趣的是,有 2 个 Packagesource Provider。 (只有一个注册且受信任的 PSRepository)

获取包源

   Name                             ProviderName     IsTrusted  Location
    ----                             ------------     ---------  --------
    PowershellAzureDevopsServices    NuGet            True       https://pkgs.dev.azure.com/...
    PSGallery                        PowerShellGet    False      https://www.powershellgallery.com/api/v2
    PowershellAzureDevopsServices    PowerShellGet    True       https://pkgs.dev.azure.com/...

在详细模式下执行 Find-Modules 时也会显示这 2 个提供程序:

Find-Module -Repository PowershellAzureDevopsServices -Credential $credsAzureDevopsServices -Verbose
AUSFÜHRLICH: Repositorydetails, Name = 'PowershellAzureDevopsServices', Location =
 'True'; IsRegistered = 'True'.
AUSFÜHRLICH: Using the provider 'PowerShellGet' for searching packages.
AUSFÜHRLICH: Die angegebenen Quellnamen werden verwendet: 'PowershellAzureDevopsServices'.
AUSFÜHRLICH: Das Anbieterobjekt für den PackageManagement-Anbieter "NuGet" wird abgerufen.
AUSFÜHRLICH: Der angegebene Speicherort ist
"https://pkgs.dev.azure.com/myorg/myprojectid/_packaging/myfeed/nuget/v2", und
PackageManagementProvider ist "NuGet".
AUSFÜHRLICH: Total package yield:'0' for the specified package ''.
'https://pkgs.dev.azure.com/myorg/myprojectid/_packaging/myfeed/nuget/v2/' for ''.
AUSFÜHRLICH: Total package yield:'2' for the specified package ''.

但最后,我不知道为什么我无法安装模块?也许你们有一些有趣的方法?

我在研究过程中发现的一些有趣的链接: GitGub MS Dev Community

但不幸的是,在这种情况下,这些链接都没有帮助我。

预先感谢您的回复。

最佳答案

我发现了导致该错误的问题。 首先,对于每一个想要使用azure devops工件发布powershell模块的人来说,你可以将文档扔进垃圾桶:( https://learn.microsoft.com/en-us/azure/devops/artifacts/tutorials/private-powershell-library?view=azure-devops )

尝试安装模块时出现问题的根本原因是错误的 .nuspec 文件。 当您像 ms 所说的那样创建 nuspec 文件时,该文件充满了占位符 xml 标记,只要您不删除这些标记,您就无法安装该模块。

唯一必要的标签是:

    <?xml version="1.0" encoding="utf-8"?>
<package >
  <metadata>
    <id>Example.Module2</id>
    <version>$VERSIONHERE$</version>
    <authors>Jon doe</authors>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <license type="expression">MIT</license>
    <!-- <icon>icon.png</icon> -->
    <description>Package description</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
  </metadata>
</package>

所有其他标签都需要删除。

因此,根据微软文档,您要做的第一件事(创建 nuspec 文件)此默认错误配置将导致最后一步(安装模块)出现错误。

幸运的是,reddit 上的这个人更详细地解释了这个问题: (https://github.com/MicrosoftDocs/azure-devops-docs/issues/12529)

关于Azure Artifacts 无法与 powershell 存储库一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75615477/

相关文章:

azure - 用于访问 Azure 上的公共(public) RESTServer 应用程序的请求 OAuth2 参数

Azure 存储模拟器无法初始化

.net - 如何以编程方式在 Azure VM 上远程安装 .NET 4 客户端?

security - 部署组 - 您无权注册目标。请联系您的发布经理以授予权限

azure-devops - 如何在 azure DevOps YAML 管道中发送构建后消息?

javascript - 如何从静态 html 网页表单发送 javascript https post 或 webhook?

azure - 有人可以解释一下 Azure AD 应用程序访问和刷新 token 的超时和验证吗?

powershell - where-object Powershell 的输入参数中的连字符

events - 在 PowerShell 中订阅对象的静态事件的语法是什么?

git - 将存储库从 Gitlab 迁移到 Azure DevOps