.net-core - Nuget 还原不适用于 Azure Devops 中的工件源

标签 .net-core azure-devops nuget azure-pipelines

NuGet 还原从同一组织中的另一个项目的提要失败 404。

当使用管道中的 nuget restore 时,找不到不同项目中的提要。

最佳答案

经过长时间的搜索,这些是使其一致工作所必需的步骤:

设置权限

  • 确保消费项目禁用了此设置
  • 项目设置(左下角)--> 管道 --> 设置 --> 将作业授权范围限制为当前项目(由另一个 answer 提供)
  • 确保将消费项目的 Build Service 添加到 feed
  • 的权限中

    设置构建管道
  • 使用 .Net Core CLI Task
  • 理想情况下,您将使用 nuget.config file 并确保在
  • 中检查它
  • feedsToUse 设置为 'config'

  • azure-pipelines.yml

    - task: DotNetCoreCLI@2
          displayName: DotNetCore-Restore
          inputs:
            command: 'restore'
            projects: '$(PathToSolution)'
            feedsToUse: 'config'
            nugetConfigPath: '$(PathToNugetConfig)/nuget.config'
            includeNuGetOrg: true
    

    配置文件

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <clear />
        <add key="feed_name" value="feed_url" />
      </packageSources>
    </configuration>
    

    无需向管道添加身份验证任务,因为 dotnet 命令会自行执行此操作...但是:

    Most dotnet commands, including build, publish, and test include an implicit restore step. This will fail against authenticated feeds, even if you ran a successful dotnet restore in an earlier step, because the earlier step will have cleaned up the credentials it used.
    - Source (.NET Core CLI task docs)

    关于.net-core - Nuget 还原不适用于 Azure Devops 中的工件源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61384798/

    相关文章:

    c# - 如何在具有不同计时器持续时间的.net核心的后台服务中运行多个任务

    c# - 在 db.database.BeginTransaction() 范围下添加时,Entity FrameWork Core 不响应 where() 查询 -Exception(请求超时)

    c# - TFS API 获取删除文件 - 更新到新版本后的不同行为(从 14xx 到 16xx)

    Azure 使用 Terraform 将安全组与多个网络接口(interface)和负载均衡器与多个子网关联

    nuget - 通过 Apache/http 服务器托管 NuGet 存储库

    nuget - 在 dotnet 包中包含自定义配置文件

    c# - 如何在 .NET Core 中以编程方式从 nuget 下载 nupkg 包?

    c# - Entity Framework 核心 - DefaultValue(true) 属性不起作用

    c# - dotnet 和 msbuild 中的包之间的区别

    azure - 如何从Azure数据存储容器获取文件夹ID?