NU1100:无法解析 Azure DevOps nuget 包

问题描述 投票:0回答:1

我们有一个 Azure DevOps nuget 包,另一个网络 api 服务可以毫无问题地使用它。但是,当将此包添加到辅助服务时,pr 管道在“恢复依赖项”步骤中失败,并出现 NU1100 错误。

管道文件

trigger:
  branches:
    exclude:
      - '*'
  paths:
    include:
      - '*'

pr:
  branches:
    include:
      - '*'

pool:
  vmImage: ubuntu-latest

variables:
  - name: vmImageName
    value: 'ubuntu-latest'

stages:
  - stage: PR
    displayName: Build and test
    jobs:
      - job: Build
        displayName: Build
        pool:
          vmImage: $(vmImageName)
        steps:
          - task: UseDotNet@2
            displayName: 'Install .NET Core SDK'
            inputs:
              packageType: 'sdk'
              version: '8.x'
              performMultiLevelLookup: true

          - task: NuGetToolInstaller@1
            displayName: 'Install NuGet'
            inputs:
              versionSpec: '6.8.0'

          - task: NuGetAuthenticate@1
            displayName: 'NuGet Authenticate'

          - task: DotNetCoreCLI@2
            displayName: 'Restore Dependencies'
            inputs:
              command: 'restore'
              projects: '**/*.csproj'
              feedsToUse: 'config'
              nugetConfigPath: 'nuget.config'
              includeNuGetOrg: true
              noCache: true

          - task: DotNetCoreCLI@2
            displayName: 'Build'
            inputs:
              command: 'build'
              projects: '**/*.csproj'
              arguments: '--configuration $(buildConfiguration) --no-restore'

      - job: Test
        displayName: Test
        pool:
          vmImage: $(vmImageName)
          steps:
            - task: NuGetAuthenticate@1
              displayName: 'NuGet Authenticate'

            - task: DotNetCoreCLI@2
              displayName: "Run Unit Tests"
              inputs:
                command: test
                projects: '**/*.UnitTests.csproj'
                arguments: '--configuration $(buildConfiguration)'

nuget.config:

<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>

  <packageSources>
    <clear />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="Custom"
         value="https://pkgs.dev.azure.com/acme/guid/_packaging/Custom/nuget/v3/index.json" />
  </packageSources>

  <packageSourceCredentials>
    <NxPro>
      <add key="Username" value="build" />
      <add key="ClearTextPassword" value="%PAT%" />
    </NxPro>
  </packageSourceCredentials>
  <packageSourceMapping>
    <packageSource key="Custom">
      <package pattern="Custom.*" />
    </packageSource>
    <packageSource key="nuget.org">
      <package pattern="*" />
    </packageSource>
  </packageSourceMapping>
</configuration>

错误:

Build FAILED.

       "/home/vsts/work/1/s/src/Infrastructure/ServiceWorker.Infrastructure.csproj" (Restore target) (1) ->
       (Restore target) -> 
         /home/vsts/work/1/s/src/Infrastructure/ServiceWorker.Infrastructure.csproj : error NU1100: Unable to resolve 'Custom.Contracts (>= 1.0.31)' for 'net8.0'. PackageSourceMapping is enabled, the following source(s) were not considered: feed-Custom, nuget.org.

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:07.64
##[error]Error: The process '/opt/hostedtoolcache/dotnet/dotnet' failed with exit code 1
##[error]Packages failed to restore
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
Finishing: Restore Dependencies

使用同一包的其他服务具有不同的 pipline 文件,其中使用 NuGetCommand@2 恢复,而不是 DotNetCoreCli@2。由于我无法理解的原因,这种方法不适用于该服务,并且一直以 MsBuild 版本错误告终。

c# azure-devops nuget-package nuget-package-restore dotnetcorecli
1个回答
0
投票

错误 NU1100:无法解析“net8.0”的“Custom.Contracts (>= 1.0.31)”。 PackageSourceMapping 已启用,未考虑以下来源:feed-Custom、nuget.org。

在您的

nuget.config
中,您已启用
<packageSourceMapping>...</packageSourceMapping>
,这会阻止 devops feed
Custom
和 nuget.org。请从 nuget.config 中删除代码。

<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>

  <packageSources>
    <clear />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="Custom"
         value="https://pkgs.dev.azure.com/acme/guid/_packaging/Custom/nuget/v3/index.json" />
  </packageSources>

  <packageSourceCredentials>
    <NxPro>
      <add key="Username" value="build" />
      <add key="ClearTextPassword" value="%PAT%" />
    </NxPro>
  </packageSourceCredentials>
</configuration>

此外,您在 nuget.config 中使用 %PAT% 进行身份验证,您可以在任务中映射

PAT
env:

          - task: DotNetCoreCLI@2
            displayName: 'Restore Dependencies'
            inputs:
              command: 'restore'
              projects: '**/*.csproj'
              feedsToUse: 'config'
              nugetConfigPath: 'nuget.config'
              noCache: true
            env:
              PAT: $(token)             #map the token variable

关于

.Net 5.x SDK/Runtime
信息,这不是错误而是信息,你可以忽略。

我这边的恢复结果:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.