skip to Main Content

I have a simple .NET 6 class library FooBarService.Contracts that contains only one DTO class FooBarRequest. I want that to be available to my team in our Azure Artifacts Feed as a NuGet package.

namespace FooBarService.Contracts.Requests;

public class FooBarRequest
{
    public string Id { get; set; }

    public FooBarRequest(string id)
    {
        Id= id;
    }
}

The azure-pipeline.yml has a stage for packing and pushing the aforementioned class library as a nuget package. I removed the irrelevant parts of the file. Update: it is the nuget push task that fails, the nuget pack task works.

pool:
  vmImage: ubuntu-latest

name: 1.0.0.0

- stage: nuget_stage
  jobs:
  - job: 'build_push_job'
    steps:
    - task: UseDotNet@2
      displayName: Use .NET 6.0
      inputs:
        packageType: 'sdk'
        version: '6.0.x'
    - task: DotNetCoreCLI@2
      inputs:
        command: 'pack'
        packagesToPack: '**/FooBarService.Contracts.csproj'
        versioningScheme: 'byBuildNumber'
    - task: DotNetCoreCLI@2
      inputs:
        command: 'push'
        packagesToPush: '$(Build.ArtifactStagingDirectory)/*.nupkg'
        nuGetFeedType: 'internal'
        publishVstsFeed: 'REDACTED_FOR_PRIVACY_REASONS/REDACTED_FOR_PRIVACY_REASONS'

All other stages are executing as planned, but this nuget_stage fails with the following error:

##[error]Error: The process '/usr/bin/dotnet' failed with exit code 1
##[error]Packages failed to publish
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

EDIT

I added the the task with Use .NET 6.0 as suggested by @Maytham Fahmi and I’m still getting the same error.

The FooBarService.Contracts.csproj file says

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <Title>FooBarService.Contracts</Title>
        <Authors />
        <LangVersion>10</LangVersion>
    </PropertyGroup>

</Project>

2

Answers


  1. Chosen as BEST ANSWER

    It turns out the displayed error was not the actual cause of the failure.

    Since the NuGet packing was successful, it could not have been .NET 6 causing the trouble. The NuGet pushing was the show stopper. I was distracted by the red error message at the bottom of the log and I didn't notice the subtle Response status code does not indicate success: 403 (Forbidden - User) Azure Pipeline at the beginning of the log.

    The solution was to switch this project's build service role from Collaborator to Contributor as described in this Stackoverflow question.


  2. you need to add this step task before all other tasks:

    - task: UseDotNet@2
      displayName: Use .NET 6.0
      inputs:
        packageType: 'sdk'
        version: '6.0.x'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search