1

We have an Azure DevOps nuget package that another service which is a net api uses without a problem. However, when this package is added to the worker service, pr pipeline fails at the "Restore Dependencies" step with NU1100 error.

Pipeline file

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>

error:

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

The other service that uses the same package has a different pipline file where instead of DotNetCoreCli@2 restore NuGetCommand@2 is used. This approach for a reason that I couldn't understand didn't work with this service and kept ending up with MsBuild version error.

4
  • The other service that uses the same package has a different pipeline... - are there any differences between the nuget.config files used in each solution? Commented Jul 5, 2024 at 12:15
  • They have exactly the same nuget.config files Commented Jul 5, 2024 at 12:17
  • What about the .NET version used in both solutions? Is it the same? Error message says Unable to resolve 'Custom.Contracts (>= 1.0.31)' for 'net8.0'. Commented Jul 5, 2024 at 12:19
  • They both use net8.0 Commented Jul 5, 2024 at 12:20

1 Answer 1

4

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.

Instead of DotNetCoreCLI@2 to restore the package, please use dotnet restore command:

          - task: PowerShell@2
            displayName: 'dotnet restore'
            inputs:
              targetType: 'inline'
              script: 'dotnet restore **/yourproject.csproj --configfile **/nuget.config'
            env:
              PAT: $(token)

You can check the similar ticket for the details.

Regarding the .Net 5.x SDK/Runtime info, it's not an error but info, you can ingore.

The restore result on my side:

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

I removed `<packageSourceMapping> but this time it failed with this error: ``` /home/vsts/work/1/s/src/Core/ServiceWorker.Core.csproj : error NU1507: Warning As Error: There are 2 package sources defined in your configuration. When using central package management, please map your package sources with package source mapping (aka.ms/nuget-package-source-mapping) or specify a single package source. The following sources are defined: nuget.org, feed-Custom ```
I reverted this change and tried only adding the PAT token but ended up with the original error
You can add the <packageSourceMapping>...</packageSourceMapping> back, but use command dotnet restore YourProject.csproj --configfile ./path/to/nuget.config to restore the package instead of DotNetCoreCLI@2. I will edit the answer with details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.