Kirsten
Kirsten

Reputation: 18170

Error NU5049 The pack command for SDK-style projects is not supported

My solution contains Framework 4.8 projects, .Net Standard 2.1 projects and .net6 projects. It has been running without problems for weeks.

Today build pipeline has started to fail with the error

##[error]The nuget command failed with exit code(1) and error(Error NU5049: The pack command for SDK-style projects is not supported, use dotnet pack or msbuild -t:pack to pack this project instead. You can override this behavior by setting the ‘NUGET_ENABLE_LEGACY_CSPROJ_PACK’ environment variable to ‘true’. Error NU5000: Failed to build package.

I tried editing the YAML to change the command from pack to dotnet pack but I get a value is not accepted error.

Error

[Update]

I am trying to see exactly how I correct the syntax. I tried typing dotnet into the tasks bar and get the following choices

I tried .Net Core but the command it inserts has -task:DotNetCoreCLI@2 which also did not work.

What is the YAML for dotnet pack ?

My YAML is as follows

trigger:
- master

pool:
  vmImage: 'windows-2022'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  Major: '2'
  Minor: '0'
  Patch: '0'

steps:
- task: NuGetToolInstaller@0
  inputs:
    versionSpec: '>=4.3.0'
    checkLatest: true

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'config'
    nugetConfigPath: 'WinFormsCoreMain\nuget.config'
    patchVersion: '$(Patch)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: DotNetCoreCLI@2
  inputs:
    command: 'pack'
    packagesToPack: '**/*.csproj'
    versioningScheme: byPrereleaseNumber
    majorVersion: '$(Major)'
    minorVersion: '$(Minor)'
 

I changed the restore command to

- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    feedsToUse: 'config'
    nugetConfigPath: 'WinFormsCoreMain\nuget.config'
    patchVersion: '$(Patch)'

This now gives an error

##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build ##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1 ##[error]An error occurred while trying to pack the files.

##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' 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

I thought I might try clicking New Pipeline to see what DevOps wanted but I git a 503 error.

503

However when I click "View our service status updates" there are no problems reported.

[Update]

Now I am able to create a new pipeline When I run it the error is

##[warning]An image label with the label vs2017-win2016 does not exist.
,##[error]The remote provider was unable to process the request.
Pool: Azure Pipelines
Image: vs2017-win2016

I will try

vmImage: 'windows-2022'

[Update]

I have rolled back and am at the point where I just want to try setting setting the 'NUGET_ENABLE_LEGACY_CSPROJ_PACK' environment variable to 'true'

[Update] As per Zar Shardan's advice I updated to use DotNetCoreCLI@2 for the pack. Then I ran into this error.

##[warning].NET 5 has some compatibility issues with older Nuget versions(<=5.7), so if you are using an older Nuget version(and not dotnet cli) to restore, then the dotnet cli commands (e.g. dotnet build) which rely on such restored packages might fail. To mitigate such error, you can either: (1) - Use dotnet cli to restore, (2) - Use Nuget version 5.8 to restore, (3) - Use global.json using an older sdk version(<=3) to build ##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1 ##[error]An error occurred while trying to pack the files.

So I tried changing the restore command to

- task: DotNetCoreCLI@2
  inputs:
    command: 'restore'
    feedsToUse: 'config'
    nugetConfigPath: 'WinFormsCoreMain\nuget.config'
    patchVersion: '$(Patch)'
    

Where upon the build started failing with messages like

 Task "Error" skipped, due to false condition; ('$(MSBuildToolsVersion)' == '2.0' and ('$(ProjectToolsVersion)' !=

'2.0' and '$(ProjectToolsVersion)' != '')) was evaluated as ('Current' == '2.0' and ('' != '2.0' and '' != '')).

and

Nuget.Config is not valid XML

and

##[error]Error: The process 'C:\Program Files\dotnet\dotnet.exe' failed with exit code 1 ##[error]Packages failed to restore

I noticed thatDotNetCoreCLI@2 does not support the

restoreSolution: '**/*.sln'

and wonder if my issue has something to do with that.

[Update]

My build YAML is

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

I think this is not working with the more recent dotnetcorecli

[Update] Trying to use DotNetCoreCLI@2 instead I ran into new problems.

Upvotes: 11

Views: 5499

Answers (3)

Joshua Duxbury
Joshua Duxbury

Reputation: 5260

From the NuGet error reference for that error, NU5059:

Issue NuGet.exe pack should not be used to generate packages for SDK-style projects.

Solution Use dotnet pack or msbuild -t:pack instead. It recommended that you do not use the legacy csproj pack experience as it generates incomplete packages.

Nuget pack command is now depreciated. This is working in Nuget version 6.4 but on version 6.5+ an error will be raise when using nuget.exe to pack an SDK.

Nuget Release Notes : Here

Merge ticket: Here

The recommendation from Nuget is to use the DotNetCLI to pack now instead due the amount of issues that can arise when using the Nuget Pack.

Upvotes: 6

Zar Shardan
Zar Shardan

Reputation: 5921

Simply replacing NuGetCommand@2 with DotNetCoreCLI@2 solves the original OP's issue:

-task: DotNetCoreCLI@2
  inputs:
command: 'pack'
    packagesToPack: '**/*.csproj'

...etc...

Upvotes: 11

Kirsten
Kirsten

Reputation: 18170

I got it working by adding

NUGET_ENABLE_LEGACY_CSPROJ_PACK: true

to

variables:

Upvotes: 7

Related Questions