【问题标题】:How to install a nuget package from another package source in azure devops pipeline?如何在 azure devops 管道中从另一个包源安装 nuget 包?
【发布时间】:2020-05-11 02:52:26
【问题描述】:

我正在尝试在 azure 上运行一些 API 测试,我之前已经能够运行我的工件,但是这个特定任务需要一个不在包源中的包:nuget.org,它是来自我工作的公司,所以当我运行管道时,我会收到以下消息:

##[error]The nuget command failed with exit code(1) and error(NU1101: Unable to find package: name of package

我在创建项目时遇到了这个问题,所以我必须添加包源,我该如何在管道上执行此操作?

【问题讨论】:

    标签: .net azure nuget devops


    【解决方案1】:

    您可以在列出包源的解决方案级别放置nuget.config file,例如

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <clear />
        <add key="your-nuget" value="https://pkgs.dev.azure.com/example/_packaging/example-nuget/nuget/v3/index.json" />
        <add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
      </packageSources>
      <activePackageSource>
        <add key="All" value="(Aggregate source)" />
      </activePackageSource>
    </configuration>
    

    请注意,这也适用于 Visual Studio(如果您通过 VS 工具菜单手动添加,您应该能够删除额外的包源)。

    然后根据您的 .net 风格,这只是在构建之前有一个步骤来恢复包的情况,DotNetCoreCLI@2(命令:restore feedsToUse:'config')或NuGetCommand@2(命令:restore feedsToUse: '配置')。

    【讨论】:

      【解决方案2】:

      如果您所说的包是您创建的自定义包,那么您需要先将 nuget 包推送到 Azure Artifact,然后您可以配置 Azure DevOps 管道以从 Azure Artifact 恢复包。

      【讨论】:

        【解决方案3】:

        假设您使用 azure devops 的问题标签,您必须在 yaml 文件中设置,恢复任务如下:

        - task: DotNetCoreCLI@2
          displayName: 'Restore Nuget Packages'
          inputs:
            command: 'restore'
            projects: '**/*.csproj'
            feedsToUse: 'select'
            vstsFeed: '<your key>'
        

        【讨论】:

          猜你喜欢
          • 2020-10-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-01-09
          • 1970-01-01
          • 2020-03-31
          • 1970-01-01
          相关资源
          最近更新 更多