Background

我正在对绿地项目的建设管道进行故障排除.之前一切都正常工作,最近我添加了一个来自同一内部Artifacts Feed的nuget包.为了确保找到所有nuget源代码[或者这就是希望],我使用了nuget. connect文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <clear />
        <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
        <add key="my-feed" value="https://pkgs.dev.azure.com/my-feed/_packaging/my-feed/nuget/v3/index.json" />
    </packageSources>
</configuration>

它用于dotnet恢复,如下所示:

  - task: DotNetCoreCLI@2
    inputs:
      command: 'restore'
      projects: '**/*.csproj'
      feedsToUse: 'config'
      nugetConfigPath: './nuget.config'
      verbosityRestore: 'Normal'

这不会出现任何故障.

The issue I am running into

下一步是运行我的单元测试,它是这样设置的(我还没有碰过它):

- task: DotNetCoreCLI@2
  displayName: 'Run Tests'
  inputs:
    command: 'test'
    projects: '**/*.tests*/*.csproj'
    arguments: '--configuration $(buildConfiguration) --collect:"XPlat Code Coverage"'
    publishTestResults: true

运行日志(log)时显示以下内容:

C:\Windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
"C:\Program Files\dotnet\dotnet.exe" test D:\a\1\s\MyProject.Tests\MyProject.Tests.csproj --logger trx --results-directory D:\a\_temp --configuration Release "--collect:XPlat Code Coverage"
  Determining projects to restore...
  Restored D:\a\1\s\MyProject.Domain\MyProject.Domain.csproj (in 80 ms).
D:\a\1\s\MyProject.Contracts\MyProject.Contracts.csproj : error NU1301: Unable to load the service index for source https://pkgs.dev.azure.com/my-feed-mes/_packaging/my-feed-mes/nuget/v3/index.json. [D:\a\1\s\MyProject.Tests\MyProject.Tests.csproj]
D:\a\1\s\MyProject.Tests\MyProject.Tests.csproj : error NU1301: Unable to load the service index for source https://pkgs.dev.azure.com/my-feed-mes/_packaging/my-feed-mes/nuget/v3/index.json.
  Failed to restore D:\a\1\s\MyProject.Contracts\MyProject.Contracts.csproj (in 7.73 sec).
  Failed to restore D:\a\1\s\MyProject.Tests\MyProject.Tests.csproj (in 7.83 sec).
D:\a\1\s\MyProject.Tests\MyProject.Tests.csproj : error NU1301: Unable to load the service index for source https://pkgs.dev.azure.com/my-feed/_packaging/my-feed/nuget/v3/index.json.
D:\a\1\s\MyProject.Tests\MyProject.Tests.csproj : error NU1301: Unable to load the service index for source https://pkgs.dev.azure.com/my-feed/_packaging/my-feed/nuget/v3/index.json.
D:\a\1\s\MyProject.Tests\MyProject.Tests.csproj : error NU1301: Unable to load the service index for source https://pkgs.dev.azure.com/my-feed/_packaging/my-feed/nuget/v3/index.json.

最终它继续运行,我不得不取消它(或者我猜它会在某个时候停止,但我不能等那么久).

My question

可能导致此错误NU 1301:无法加载服务索引 源错误以及如何解决它?

除了添加内部nuget包(并使用nuget. connect来确定服务器上的源代码正确)之外,没有任何更改.

推荐答案

根据您的描述,dotnet恢复步骤可以成功恢复包,但dotnet测试步骤将显示NU 1301错误.

问题的原因是dotnet恢复步骤将清理其使用的凭据.那么在dotnet测试步骤中无法读取有效凭据.

参考此文档:Why is my build, publish, or test step failing to restore packages?

大多数dotnet命令(包括构建、发布和测试)都包含隐式恢复步骤.即使您在较早的步骤中成功运行了dotnet恢复,这对经过验证的提要也会失败,因为较早的步骤将清理它使用的凭据.

由于您已在Pipeline中添加了dotnet恢复步骤,因此可以在dotnet测试步骤中添加参数:--no-restore以跳过隐式恢复步骤.

例如:

- task: DotNetCoreCLI@2
  displayName: 'Run Tests'
  inputs:
    command: 'test'
    projects: '**/*.tests*/*.csproj'
    arguments: '--no-restore --configuration $(buildConfiguration) --collect:"XPlat Code Coverage"'
    publishTestResults: true

另一方面,由于单独的dotnet恢复步骤运行良好,因此我们可以确认项目中的其他与feed相关的设置是否正确.

Csharp相关问答推荐

VB.Net的SON模式导致集合代码不工作

PredicateBuilder不是循环工作,而是手动工作

C#使用属性和值将JSON转换为XML

如何保持主摄像头视角保持一致?

Azure Function应用(. NET 8)不将信息记录到应用洞察

.NET 6控制台应用程序,RabbitMQ消费不工作时,它的程序文件中的S

为什么EventInfo.EventHandlerType返回可为空的Type值?

如何注册类使用多级继承与接口

为什么AggregateException的Catch块不足以处理取消?

当试图限制EF Select 的列时,如何避免重复代码?

如何管理Azure认证客户端响应和证书 fingerprint

LINQ to Entities中的加权平均值

在Docker容器中运行API项目时,无法本地浏览到index.html

在C#中过滤Excel文件

在集成测试中可以在模拟InMemory数据库中设定数据种子

C#中类库项目的源代码生成器

如何使用.NET Aspire从Blazor应用程序与GRPC API通信?

映射器-如何映射到多个实体

如何使用moq和xUnit对删除操作进行单元测试?

Windows 10上埃及标准时间的时区偏移不正确