21

I'm getting

Unable to resolve 'NETStandard.Library (>= 1.6.1)' for '.NETStandard,Version=v2.0'.

in VSTS build using Hosted2017 build agent after I upgraded my aspnetcore app to netcoreapp2.0 and my libraries to use netstandard2.0.

Works fine locally.

I've edited my build definition to use .net core build task v2.* preview:

build definition details

here is the build log:

Current agent version: '2.120.2'
Download all required tasks.
Downloading task: DotNetCoreCLI

Starting: Get Sources
Syncing repository: Liero/vyvojari-sk (GitHub)
...details ommited
HEAD is now at e448a25... Upgraded to .NET Core 2.0
Finishing: Get Sources

Starting: Restore
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet.
Version      : 2.0.5
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?linkid=832194)
==============================================================================
SYSTEMVSSCONNECTION exists true
Downloading: https://dist.nuget.org/win-x86-commandline/v4.0.0/nuget.exe
Caching tool: NuGet 4.0.0 x64
Using version: 4.0.0
Found tool in cache: NuGet 4.0.0 x64
Saving NuGet.config to a temporary config file.
Can\'t find loc string for key: NGCommon_NoSourcesFoundInConfig
NGCommon_NoSourcesFoundInConfig d:\a\1\Nuget\tempNuGet_734.config
"C:\Program Files\dotnet\dotnet.exe" restore d:\a\1\s\src\CommandStack\CommandStack.csproj --configfile d:\a\1\Nuget\tempNuGet_734.config --verbosity Detailed
  Restoring packages for d:\a\1\s\src\CommandStack\CommandStack.csproj...
C:\Program Files\dotnet\sdk\1.0.4\NuGet.targets(97,5): error : Unable to resolve 'NETStandard.Library (>= 1.6.1)' for '.NETStandard,Version=v2.0'. [d:\a\1\s\src\CommandStack\CommandStack.csproj]
  Generating MSBuild file d:\a\1\s\src\CommandStack\obj\CommandStack.csproj.nuget.g.props.
  Generating MSBuild file d:\a\1\s\src\CommandStack\obj\CommandStack.csproj.nuget.g.targets.
  Writing lock file to disk. Path: d:\a\1\s\src\CommandStack\obj\project.assets.json
  Restore failed in 115.64 ms for d:\a\1\s\src\CommandStack\CommandStack.csproj.

  Errors in d:\a\1\s\src\CommandStack\CommandStack.csproj
      Unable to resolve 'NETStandard.Library (>= 1.6.1)' for '.NETStandard,Version=v2.0'.

  NuGet Config files used:
      d:\a\1\Nuget\tempNuGet_734.config
Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1
Packages failed to restore
******************************************************************************
Finishing: Restore
******************************************************************************

and here is the source code: https://github.com/Liero/vyvojari-sk/tree/e448a25fb8c481704e9102aaaeb8b84b9aee7b02

Liero
  • 25,216
  • 29
  • 151
  • 297
  • Looks like the 1.0.4 SDK is used on the agent and the hosted agent probably wasn't yet updated with the 2.0.0 SDK – Martin Ullrich Aug 16 '17 at 15:34
  • But you see that v2.0.5 is used in the restore task – Liero Aug 16 '17 at 15:57
  • that's the task. I see `C:\Program Files\dotnet\sdk\1.0.4` – Martin Ullrich Aug 16 '17 at 16:02
  • I've also added .NET Core Tool Installer task that install v2.0.0 and still the same output – Liero Aug 16 '17 at 16:05
  • Hmm, it looks like when I checked "Feed(s) I select here" rather than preselected "Feeds in my NuGet.config" and make sure that "Use packages from NuGet.org" is also checked it works. Could someone verify this? – Liero Aug 16 '17 at 16:11

5 Answers5

66

Update 18/09/2017

Step 2 is no longer needed. I've left it in the solution though as it may still help some people. Thanks, @Liero for point this out.


Original Answer

I've just experienced this problem too and solved it by doing three things:

  1. Use the .NET Core SDK(! - not runtime!) version 2.0.0: enter image description here

  2. Use the latest NuGet feed (4.3.0): enter image description here

  3. Restore your packages: enter image description here

Update It's worth mentioning here that you should specify where you get your NuGet packages from. Most applications will probably just use the NuGet.org feed, as per the screenshot (see small checkbox), but you may have your custom feeds specified in a NuGet.config file. In that case, tick 'Feeds in my NuGet.config' and then specify the path to that file.

To illustrate the order, this is my working queue: enter image description here

I hope this helps you and anyone else who has come up against this problem. If you have any questions, let me know. :)

Chris Paton
  • 5,113
  • 4
  • 41
  • 52
  • In my case it worked also when I disabled use *Use Nuget 4.3* (resp `4.*` in my case), but maybe its because the tool was already cached. – Liero Aug 18 '17 at 07:43
  • Amazing. My hat's off to you, friend! – Ben Aug 19 '17 at 07:26
  • I'm still getting error "Error: d:\a\_tool\dncs\2.0.0\x64\dotnet.exe failed with return code: 1 Packages failed to restore" – Pankaj Rawat Aug 20 '17 at 09:35
  • @PankajRawat are you sure you're using the latest version of nuget and have you told it to get your packages from nuget.org (if you don't have a packages directory)? – Chris Paton Aug 20 '17 at 10:01
  • @ChrisPaton Yes I don't have package directory. https://s28.postimg.org/bj340omd9/Capture.jpg – Pankaj Rawat Aug 20 '17 at 10:33
  • @PankajRawat what is the output from your restore log when it fails? – Chris Paton Aug 20 '17 at 13:20
  • Thanks a lot. Worked like a charm. Microsoft better document this. – Rukshan Dangalla Aug 20 '17 at 16:44
  • @ChrisPaton. error I'm getting on restore "error NU1003: PackageTargetFallback and AssetTargetFallback cannot be used together. Remove PackageTargetFallback(deprecated) references from the project environment.", See detail error log https://1drv.ms/u/s!At8hAhHRFiWTwA43mlwqiW1P7Gbt – Pankaj Rawat Aug 21 '17 at 03:32
  • @PankajRawat I would suggest doing what the error says and remove PackageTargetFallback as it is deprecated! :) – Chris Paton Aug 21 '17 at 13:00
  • @ChrisPaton. It's working. thank u so much. https://github.com/dotnet/buildtools/commit/f99e5ef88ac3e6b909676619a309147283f7c241 – Pankaj Rawat Aug 21 '17 at 15:44
  • maybe this would work if I would know what IDE you are using and how to get to the screens you posted. Could you please update! – Andrei Dobrin Aug 23 '17 at 13:50
  • @AndreiDobrin this question is about VSTS build configurations. The OP posted pictures from VSTS so I assumed a certain level of knowledge. Anyone familiar with VSTS will recognise these images. IDE is irrelevant here. – Chris Paton Aug 23 '17 at 14:11
  • Great help, thanks! In my case I had to leave "Feeds in my NuGet.config" toggled as I am using the aspnet-contrib feed as well as the NuGet feed and otherwise it could not resolve aspnet-contrib packages. – Yogster Aug 24 '17 at 15:00
  • Steps 1 and 2 worked for me, but step 3 did not. Instead I changed the Version of the NuGet from 1.* to 2.*. Possibly this is a timing issue as by now VSTS improved their support. Ludicrous how Microsoft's build servers don't support their stuff when they release it. But anyway, now I have to come back here later I guess and keep manually increasing the NuGet version? Annoying. I want a "Always use latest version" option. – user2415376 Sep 01 '17 at 13:18
  • @ChrisPaton: it looks like step 2 (Nuget Installer Task) is no more required. – Liero Sep 18 '17 at 10:35
  • These steps didn't work for me, sadly. I still experience this error. – Ben Collins Dec 04 '17 at 16:49
  • @ChrisPaton: Maybe you should add to your step 3, that "Feed(s) I select here" option has to be checked OR you have to have nuget.config in your sources – Liero Dec 08 '17 at 07:57
  • I've made that change, @Liero. – Chris Paton Dec 08 '17 at 16:57
  • Sorry to hear that @Ben Collins. After adding these steps, where does your build process fail? – Chris Paton Dec 08 '17 at 16:59
  • @ChrisPaton it turned out that I needed to be sure that the `packet install` command was run prior to any of the rest of it. Isaac Abraham has provided a very helpful extension package for VSTS (F# Helpers for VSTS) that includes a task to do just that. – Ben Collins Dec 10 '17 at 04:15
4

You should select Feed(s) I select here for Feeds to use option. If you leave Use packages from this VSTS/TFS feed empty, packages will be downloaded from https://dist.nuget.org/.

enter image description here

Else, if you want to use Feeds in my NuGet.config as Feeds to use, you should specify the path for your NuGet.config file.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74
  • 1
    Actually, it works with both .NET Core task `2.* (preview)` and `1.*`, but I had to add *.NET Core Tool Installer* build task. Could it be that my build agent was not updated yet? In `2.* ` of the restore task, I had to *unselect "Feeds in my Nuget.config"*, since I have none. Maybe it could default to nuget.org package source? – Liero Aug 17 '17 at 07:13
  • Thank you. However, this step alone is not sufficient. Without the *.NET Core Tool Installer* build task it does not work in my case. – Liero Aug 17 '17 at 09:54
  • Ok, since you have solved the problem, you can add an answer for your steps and mark it. Or if your solved steps as Chris mentioned in the other answer, you can mark his answer. And it will also benefit others who have similar questions. – Marina Liu Aug 18 '17 at 06:34
1

I have received a similar error after generating a project using dotnet new angular which created a project relying on netcoreapp2.0. Inspection of project properties revealed that version 2.0 was not properly recognized (did not appear in the installed framework list).

Solution was to update Visual Studio 2017, as the minimum version required to support netcoreapp2.0 projects seems to be 15.3.1.

Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
0

What worked for me was installing .NET Core SDK 2.0 and making the following changes:

in .csproj:

change

<TargetFramework>netcoreapp1.1.0</TargetFramework>

to

<TargetFramework>netcoreapp2.0</TargetFramework>

and in global.json:

"sdk": { "version": "1.1.0" }

to

"sdk": { "version": "2.0.0" }

I didn't know how to use Chris Paton' solution

Andrei Dobrin
  • 1,164
  • 4
  • 19
  • 35
0

Updating the Visual Studio 2017 to latest 15.4.1 version resolved the problem for me.

Megha
  • 509
  • 5
  • 16
  • 1
    Are you sure? Because this problem is related to VSTS not Visual Studio? – Liero Oct 26 '17 at 15:05
  • I was getting same error with Visual Studio build after upgrading to .netCore 2.0. I had Visual studio version 15.2. Problem was resolved after updating visual studio to latest version 15.4.1 – Megha Oct 26 '17 at 15:38