'Nuget Pack in Azure Pipelines: The method or operation is not implemented

I am trying to build a DotNetCore project and push the package to Azure Artifacts.

The Azure-Pipelines.yml I have is the following:

trigger:
- master

pool:
  vmImage: 'Ubuntu-16.04'

variables:
  buildConfiguration: 'Release'
  buildPlatform: 'any cpu'
  version: '1.0.0'

steps:

- task: DotNetCoreInstaller@0
  displayName: 'Install'
  inputs:
    packageType: 'sdk'
    version: '2.2.105'

- task: DotNetCoreCLI@2
  displayName: 'Restore'
  inputs:
    command: restore
    projects: '**/*.csproj'

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

- task: NuGetCommand@2
  displayName: 'Pack'
  inputs:
    command: pack
    versioningScheme: byEnvVar
    versionEnvVar: version

- task: NuGetCommand@2
  displayName: 'Push'
  inputs:
    command: push
    publishVstsFeed: 'myfeed' 

It fails on task Pack with the error:

Caching tool: NuGet 4.1.0 x64
Found tool in cache: NuGet 4.1.0 x64
Resolved from tool cache: 4.1.0
Using version: 4.1.0
Found tool in cache: NuGet 4.1.0 x64
Attempting to pack file: /home/vsts/work/1/s/MyProject.csproj
[command]/usr/bin/mono /opt/hostedtoolcache/NuGet/4.1.0/x64/nuget.exe pack /home/vsts/work/1/s/MyProject.csproj -NonInteractive -OutputDirectory /home/vsts/work/1/a -Properties Configuration=Release -version 1.0.0 -Verbosity Detailed
System.NotImplementedException: The method or operation is not implemented.
NuGet Version: 4.1.0.2450
  at (wrapper dynamic-method) System.Object.CallSite.Target(System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object)
Attempting to build package from 'MyProject.csproj'.
  at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid1[T0] (System.Runtime.CompilerServices.CallSite site, T0 arg0) [0x00108] in <48b97f13fd854060ad87a12d847b0428>:0 
MSBuild auto-detection: using msbuild version '14.0' from '/usr/lib/mono/xbuild/14.0/bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
  at NuGet.CommandLine.ProjectFactory.ResolveTargetPath () [0x00345] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.CommandLine.ProjectFactory.BuildProject () [0x0016e] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.CommandLine.ProjectFactory.CreateBuilder (System.String basePath, NuGet.Versioning.NuGetVersion version, System.String suffix, System.Boolean buildIfNeeded, NuGet.Packaging.PackageBuilder builder) [0x00015] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.Commands.PackCommandRunner.BuildFromProjectFile (System.String path) [0x00140] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.Commands.PackCommandRunner.BuildPackage (System.String path) [0x00033] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.Commands.PackCommandRunner.BuildPackage () [0x00021] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.CommandLine.PackCommand.ExecuteCommand () [0x001fe] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.CommandLine.Command.ExecuteCommandAsync () [0x00000] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.CommandLine.Command.Execute () [0x000b7] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.CommandLine.Program.MainCore (System.String workingDirectory, System.String[] args) [0x001f3] in <d0f788a4af354971807e5d8ca6fc682e>:0 
##[error]The nuget command failed with exit code(1) and error(System.NotImplementedException: The method or operation is not implemented.
  at (wrapper dynamic-method) System.Object.CallSite.Target(System.Runtime.CompilerServices.Closure,System.Runtime.CompilerServices.CallSite,object)
  at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid1[T0] (System.Runtime.CompilerServices.CallSite site, T0 arg0) [0x00108] in <48b97f13fd854060ad87a12d847b0428>:0 
  at NuGet.CommandLine.ProjectFactory.ResolveTargetPath () [0x00345] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.CommandLine.ProjectFactory.BuildProject () [0x0016e] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.CommandLine.ProjectFactory.CreateBuilder (System.String basePath, NuGet.Versioning.NuGetVersion version, System.String suffix, System.Boolean buildIfNeeded, NuGet.Packaging.PackageBuilder builder) [0x00015] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.Commands.PackCommandRunner.BuildFromProjectFile (System.String path) [0x00140] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.Commands.PackCommandRunner.BuildPackage (System.String path) [0x00033] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.Commands.PackCommandRunner.BuildPackage () [0x00021] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.CommandLine.PackCommand.ExecuteCommand () [0x001fe] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.CommandLine.Command.ExecuteCommandAsync () [0x00000] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.CommandLine.Command.Execute () [0x000b7] in <d0f788a4af354971807e5d8ca6fc682e>:0 
  at NuGet.CommandLine.Program.MainCore (System.String workingDirectory, System.String[] args) [0x001f3] in <d0f788a4af354971807e5d8ca6fc682e>:0)
##[error]An error ocurred while trying to pack the files.
##[section]Finishing: Pack

I tried many configurations but I am not able to remove the error.

What am I missing?



Solution 1:[1]

Above problem can be solved by using

pool:
  vmImage: 'ubuntu-latest' // which is 20.04

I tried this and it solved the problem. For clarity i used the MS hosted agent and agent version is 2.200.2

May be using the Self hosted agent(missing nuget installation or in correct version of nuget) or a diff version of ubuntu is the cause of the issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GPuri