Dim_Ka
Dim_Ka

Reputation: 786

Problem with restoring nuget packages with asp.net core 2.2

I successfully update my projects to netcoreapp2.2. I can restore nuget packages and build the projects without any problems. I use CD/CI and on the build server I receive error message when I restore the nugets. These is from the log:

2018-12-14T12:35:33.4556576Z ##[error]The nuget command failed with exit code(1) and error(NU1607: Version conflict detected for Microsoft.AspNetCore.Authentication.Abstractions. Reference the package directly from the project to resolve this issue. PM.Service.API (>= 1.0.0) -> Microsoft.AspNetCore.Mvc.Formatters.Xml (>= 2.2.0) -> Microsoft.AspNetCore.Mvc.Core (>= 2.2.0) -> Microsoft.AspNetCore.Authorization.Policy (>= 2.2.0) -> Microsoft.AspNetCore.Authentication.Abstractions (>= 2.2.0) PM.Service.API (>= 1.0.0) -> Microsoft.AspNetCore.App (>= 2.1.0) -> Microsoft.AspNetCore.Authentication.Abstractions (>= 2.1.0). NU1607: Version conflict detected for Microsoft.AspNetCore.Hosting. Reference the package directly from the project to resolve this issue. TM.Service.API (>= 1.0.0) -> Microsoft.AspNetCore.Hosting.WindowsServices (>= 2.2.0) -> Microsoft.AspNetCore.Hosting (>= 2.2.0) TM.Service.API (>= 1.0.0) -> Microsoft.AspNetCore.App (>= 2.1.0) -> Microsoft.AspNetCore.Hosting (>= 2.1.0).

In my project I have these package references:

How can I resolve this issue? Thanks

Upvotes: 2

Views: 5566

Answers (7)

nammadhu
nammadhu

Reputation: 1

Update the configuration: Update the version of nuget.exe from 4.3.0 to 4.8.1 and now it works. Looks like older version having some issue in settling

If yaml file then update as below,

  • task: NuGetToolInstaller@0 inputs: versionSpec: '4.8.1'

Upvotes: 0

BartKrul
BartKrul

Reputation: 657

I had the same problem. Locally, the project would restore Nuget packages just fine, but as soon as I started using Azure Pipelines, I got the version conflict error.

I ended up changing this in my yaml file:

- task: NuGetToolInstaller@0
  inputs:
    versionSpec: '4.8.1' <-- Define the Nuget version here

After that the restore Nuget packages step in my pipeline worked just fine.

Upvotes: 2

maeneak
maeneak

Reputation: 623

I installed ASPNetCore 2.2 locally, retargeted to 2.2 in project props, removed existing 2.1 references in nuget PM and then installed Microsoft.Aspnetcore (2.2) through nuget. Fixed.

Upvotes: 0

G-Ram
G-Ram

Reputation: 33

I had a similar issue as Dim_Ka. I was using Nuget v4.3. I tried disabling the cache when doing a nuget restore and that didn't work. I updated to Nuget v4.8.1 and the nuget restore successfully worked.

After that, I went back to Nuget 4.3 just to confirm that 4.3 was causing the issue and it started failing again . Then changed it back to 4.8.1 and it started working again.

This was the error I was receiving:

The nuget command failed with exit code(1) and error(NU1607: Version conflict detected for Microsoft.AspNetCore.Authentication.Core. Reference the package directly from the project to resolve this issue. ThisApp.API (>= 1.0.0) -> Microsoft.AspNetCore.Mvc.Versioning (>= 3.1.1) -> Microsoft.AspNetCore.Mvc.Core (>= 2.2.0) -> Microsoft.AspNetCore.Authentication.Core (>= 2.2.0) ThisApp.API (>= 1.0.0) -> Microsoft.AspNetCore.App (>= 2.1.0) -> Microsoft.AspNetCore.Authentication.Core (>= 2.1.0). Errors in D:\a\1\s\ThisApp.API\ThisApp.API.csproj NU1607: Version conflict detected for Microsoft.AspNetCore.Authentication.Core. Reference the package directly from the project to resolve this issue. ThisApp.API (>= 1.0.0) -> Microsoft.AspNetCore.Mvc.Versioning (>= 3.1.1) -> Microsoft.AspNetCore.Mvc.Core (>= 2.2.0) -> Microsoft.AspNetCore.Authentication.Core (>= 2.2.0) ThisApp.API (>= 1.0.0) -> Microsoft.AspNetCore.App (>= 2.1.0) -> Microsoft.AspNetCore.Authentication.Core (>= 2.1.0).) Packages failed to restore

I am assuming it has to do with the fact that you aren't supposed to specify the version for the Microsoft.Aspnetcore.App package. Nuget 4.3 might not be able to handle that correctly going forward: https://learn.microsoft.com/en-us/aspnet/core/migration/21-to-22?view=aspnetcore-2.2&tabs=visual-studio#update-package-references

Upvotes: 0

Dim_Ka
Dim_Ka

Reputation: 786

Thank you for your answers. I found the problem. I have a task "NuGet Tool Installer" in my CD process. I update the version of nuget.exe from 4.3.0 to 4.8.1 and now it works. Thank you

Upvotes: 7

Gabriel Luci
Gabriel Luci

Reputation: 40998

The error is saying that multiple packages that you have installed are dependent on these packages:

  • Microsoft.AspNetCore.Authentication.Abstractions
  • Microsoft.AspNetCore.Hosting

But different packages are dependent on different versions. Notice the different version numbers asked for: "(>= 1.0.0)", "(>= 2.1.0)", "(>= 2.2.0)".

Really, version 2.2.0 will satisfy all of those conditions, but it's still confused, so it doesn't know which version to install.

The solution is to "Reference the package directly from the project", or in other words, install those two packages explicitly.

Upvotes: 1

Derviş Kayımbaşıoğlu
Derviş Kayımbaşıoğlu

Reputation: 30645

PM.Service.API references Microsoft.AspNetCore.App which is version 2.1.x

You need to upgrade your class libraries as well

Upvotes: 0

Related Questions