61

It's my own custom nuget package that I've not published yet and testing locally.

The nuget package consists of a dll file and nuspec file is as follows.

<?xml version="1.0"?>
<package >
  <metadata>
    <id>MyLib</id>
    <version>1.0.0</version>
    <authors>Author</authors>
    <owners>Owner</owners>
    <licenseUrl>license url</licenseUrl>
    <projectUrl>project url</projectUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>some description</copyright>
    <tags>Tag1 Tage2</tags>
  </metadata>
  <files>
    <file src="bin\Debug\netstandard1.4\*.dll" target="lib" />
    <file src="bin\Debug\netstandard1.4\*.pdb" target="lib" />
  </files>
</package>

I've copied the nupkg file to a location and added it to the

Visual studio Tools -> Options -> Packages -> sources directory 

Error:

Package MyLib 1.0.0 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package MyLib 1.0.0 supports: net (.NETFramework,Version=v0.0)
Package restore failed. Rolling back package changes for 'WebApplication1'.

Not sure how can I resolve the issue or find more information.

More Info

The dll file was created using template (.Net Framework 4.5.2)

Templates -> Visual C# -> .NET Core -> Class Library (.NET Standard)

The web application was crated using template. (Empty Web Application)

Templates -> Visual C# -> .NET Core -> ASP.NET Core Web Application (.NET Core)

Edit

I found more details under Output window

One or more packages are incompatible with .NETCoreApp,Version=v1.0.

What kind of class library should I create which is compatible with .NETCoreApp?

Edit2

I saw this URL. it suggests to create the nupkg using dotnet.exe pack --no-build whereas earlier I downloaded the nuget.exe from nuget.org to create the package.

I tried above command but then visual studio says

"... Target pack doesn't exists in the project ... "

Followed instructions on this site as well but failed URL

user2727195
  • 7,122
  • 17
  • 70
  • 118
  • 1
    sorry for confusion, why did you mention .Net Framework 4.5.2 if you want to target .netcore? – Oleg Bogdanov Feb 06 '17 at 03:00
  • yes it's confusing for me too, when I select `New Project -> Templates -> .Net Core -> Class Library Framework (.NET Standard)`, the .NET Framework 4.5.2 is listed on the top of the dialog box in the drop down menu (that's why I mentioned), so I'm not sure what kind of project template should I pick to create the right kind of dll to be used with .net core. – user2727195 Feb 06 '17 at 03:08
  • Have you seen this [one](https://learn.microsoft.com/en-us/nuget/guides/create-net-standard-packages-vs2017) ? Namely that `With NuGet 4.0 and .NET Core projects, package metadata is contained directly in the .csproj ` – Oleg Bogdanov Feb 06 '17 at 05:14
  • Did you changed your application name or namespace? – Aravin Jun 10 '17 at 06:07
  • @user2727195 friend please acc my answer – Shahrooz Ansari Oct 01 '17 at 18:52
  • Are you trying to reference NetStandard in such way? You are doing something wrong – Vlad DX Feb 06 '18 at 06:50

3 Answers3

162

You need clear the Nuget Cache. To do this, go to Tools -> Options and click on it like this picture enter image description here

user2441511
  • 11,036
  • 3
  • 25
  • 50
Shahrooz Ansari
  • 2,637
  • 1
  • 13
  • 21
27

Your project is targetting an incompatible version of .Net Framework. Right click on the project, select properties and note the value of the Target Framework. Look at the Nuget package for Microsoft and then install a more suitable NuGet package. Either install the older version of the NuGet package or update your project to target a newer version.

CodeMonkey
  • 2,511
  • 4
  • 27
  • 38
  • 2
    I ran into the OP's error because I added a Class Library (Standard) instead of Class Library (Framework). This answer made me realize the issue. – ScubaSteve Jan 31 '18 at 15:35
1

I had to change the Build Configuration due to an NU1603: warning.

In my Build configuration the "Treat warnings as errors" was set to All.

This was blocking Nuget from upgrading the Package due to the NU1603 warning. enter image description here

Pascalsz
  • 1,092
  • 11
  • 10