1
votes

My project was building without errors but with a warning

NETSDK1071 A PackageReference to 'Microsoft.AspNetCore.App' specified a Version of 2.1.1. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs

So I edited the project and changed

  <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1"/>

to

 <PackageReference Include="Microsoft.AspNetCore.App" />

I pushed the code which then triggers devops to build.

However in Devops I then got the following build error

The nuget command failed with exit code(1) and error(NU1607: Version conflict detected for Microsoft.AspNetCore.Razor.Language. Reference the package directly from the project to resolve this issue. 
 ServerSideTests (>= 1.0.0) -> ApiForMe3 (>= 1.0.0) -> Microsoft.VisualStudio.Web.CodeGeneration.Design (>= 2.1.6) -> Microsoft.VisualStudio.Web.CodeGenerators.Mvc (>= 2.1.6) -> Microsoft.VisualStudio.Web.CodeGeneration (>= 2.1.6) -> Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore (>= 2.1.6) -> Microsoft.VisualStudio.Web.CodeGeneration.Core (>= 2.1.6) -> Microsoft.VisualStudio.Web.CodeGeneration.Templating (>= 2.1.6) -> Microsoft.AspNetCore.Razor.Language (>= 2.1.1) 
 ServerSideTests (>= 1.0.0) -> Microsoft.AspNetCore.App (>= 2.1.0) -> Microsoft.AspNetCore.Razor.Language (>= 2.1.0).
Errors in D:\a\1\s\ServerSideTests\ServerSideTests.csproj
    NU1607: Version conflict detected for Microsoft.AspNetCore.Razor.Language. Reference the package directly from the project to resolve this issue.
     ServerSideTests (>= 1.0.0) -> ApiForMe3 (>= 1.0.0) -> Microsoft.VisualStudio.Web.CodeGeneration.Design (>= 2.1.6) -> Microsoft.VisualStudio.Web.CodeGenerators.Mvc (>= 2.1.6) -> Microsoft.VisualStudio.Web.CodeGeneration (>= 2.1.6) -> Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore (>= 2.1.6) -> Microsoft.VisualStudio.Web.CodeGeneration.Core (>= 2.1.6) -> Microsoft.VisualStudio.Web.CodeGeneration.Templating (>= 2.1.6) -> Microsoft.AspNetCore.Razor.Language (>= 2.1.1)
     ServerSideTests (>= 1.0.0) -> Microsoft.AspNetCore.App (>= 2.1.0) -> Microsoft.AspNetCore.Razor.Language (>= 2.1.0).)
Packages failed to restore

Why does the build fail in Devops but not on my local machine running VS2017 15.9.6 ?

looking up NU1607 I see

NU1107 (Previously NU1607) Issue Unable to resolve dependency constraints between packages.

Common causes
Packages with dependency constraints on exact versions do not allow other packages to increase the version if needed.

Example
Version conflict detected for NuGet.Versioning. Reference the package directly from the project to resolve this issue.
  NuGet.Packaging 3.5.0 -> NuGet.Versioning (= 3.5.0)
  NuGet.Configuration 4.0.0 -> NuGet.Versioning (= 4.0.0)

Checking the sdk versions on my machine

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional>dotnet --list-sdks
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.400 [C:\Program Files\dotnet\sdk]
2.1.401 [C:\Program Files\dotnet\sdk]
2.1.402 [C:\Program Files\dotnet\sdk]
2.1.403 [C:\Program Files\dotnet\sdk]
2.1.500 [C:\Program Files\dotnet\sdk]
2.1.502 [C:\Program Files\dotnet\sdk]
2.1.503 [C:\Program Files\dotnet\sdk]
2.2.102 [C:\Program Files\dotnet\sdk]
2
What's the .NET Core SDK version on your local machine and DevOps agent? You probably should add a global.json to enforce a version check.Lex Li
I updated the question to show I have a fewKirsten
I am building locally using Visual Studio so I aren't sure global.json is relevant?Kirsten
Starting from recent SDK releases, the package versions are controlled by the SDK itself. Thus, to make sure your project always compiles on different machines, it is not a bad idea to leave a global.json with a specific version. In that way, if the target machine does not have the same SDK version, at least you or somebody else get a meaningful error message.Lex Li

2 Answers

3
votes

I had a similar issue using TeamCity.

In TeamCity I changed NuGet version for NuGet Installer step.

Upgraded from Nuget.exe version 4.3 to 5.1

Problem is gone

0
votes

The error I was getting:

The nuget command failed with exit code(1) and error(NU1607: Version conflict detected for Microsoft.AspNetCore.Http.Abstractions. Reference the package directly from the project to resolve this issue. 
 Service.Api (>= 1.0.0) -> Common.Middleware (>= 1.0.0) -> Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0) 
 Service.Api (>= 1.0.0) -> Microsoft.AspNetCore.App (>= 2.1.0) -> Microsoft.AspNetCore.Http.Abstractions (>= 2.1.0).
Errors in d:\a\1\s\src\Service.Api\Service.Api.csproj
    NU1607: Version conflict detected for Microsoft.AspNetCore.Http.Abstractions. Reference the package directly from the project to resolve this issue.
     Service.Api (>= 1.0.0) -> Common.Middleware (>= 1.0.0) -> Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
     Service.Api (>= 1.0.0) -> Microsoft.AspNetCore.App (>= 2.1.0) -> Microsoft.AspNetCore.Http.Abstractions (>= 2.1.0).)
Packages failed to restore

So I made a change in .csproj file:

<ItemGroup>
  <PackageReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

to:

<ItemGroup>
  <PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.0" />
</ItemGroup>

However, that did NOT fix the issue. (So I reverted the above changes)

Because I started getting this error:

(Output window)

>C:\Program Files\dotnet\sdk\2.2.107\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(153,5): warning NETSDK1071: A PackageReference to 'Microsoft.AspNetCore.App' specified a Version of `2.2.0`. Specifying the version of this package is not recommended. For more information, see https://aka.ms/sdkimplicitrefs

(Build pipeline MSBUILD task)

Services.FastService.Api.csproj : error : NETSDK1061: The project was restored using Microsoft.NETCore.App version 1.0.0, but with current settings, version 2.2.0 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore. For more information, see https://aka.ms/dotnet-runtime-patch-selection.

Therefore I tried this:

<PropertyGroup>
  <TargetFramework>netcoreapp2.2</TargetFramework>
  <TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>

As others have suggested, such as in this thread: Version 2.1.0-rc1 would be used instead

But that didn't help me at all. (So I reverted that change as well.)

Eventually I realized that because MSBUILD doesn't like it when you specify a minimum version for Microsoft.AspNetCore.App, that the default minimum versions were different:

  1. Service.Api Common.Middleware (>= 1.0.0) Microsoft.AspNetCore.Http.Abstractions (>= 2.1.0)

  2. Common.Middleware Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)

Therefore I changed the minimum version in my Common.Middleware project from '2.2.0' to '2.1.0'.

But that didn't seem to fix all my issues either!

I also tried this:

2.2.0

so:

<PropertyGroup>
  <TargetFramework>netcoreapp2.2</TargetFramework>
  <RuntimeFrameworkVersion>2.2.0</RuntimeFrameworkVersion>
  <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>

But that didn't help either...

Finally I specified the use of NuGet 5.1.0 in my YAML build script and that fixed the project.

(So upvote to Jacob Sandh0j)

ThE FInaL SOLuTioN

YAML

- task: NuGetToolInstaller@0
  inputs:
    versionSpec: '5.1.0' 
    checkLatest: false