3

I think that I am fundamentally missing something here and I apologise for stupidity in advance. Trying to embrace the new world of dotnet core and working on a project as a way of trying to learn.

I have written some authentication middleware to work for with ASP.NET Core Identity. I have used a .NET Core Class Library for the middleware - the advantage being that I believe I can then potentially target any framework as well as build Nuget packages of my component. The middleware works fine when used with an ASP.NET Core Web app targetting .NET Core - based on the VS2015 RC2 template.

Feeling adventurous I decided to create a version of the component based around OWIN/Katana authentication middleware so I could use it with ASP.NET 4.5/6 web applications. Instead of creating a traditional class library project I once again used the .NET Core Class Library template but targetted it only at .NET 4.6, i.e. net46. It compiles fine but I cannot get my ASP.NET 4.6 application to reference it. I followed the information in this SO question to create a NuGet package, create a local source and then try to add it to my ASP.NET 4.6 project but it fails with the error:

Unable to resolve dependency 'NETStandard.Library'. Source(s) used: 'nuget.org', 'AspNetRc2Source', 'MyGet', 'Local', 'Microsoft and .NET', 'Microsoft Visual Studio Offline Packages'. 0

My head is spinning with dependencies and frameworks.

Anyway here is the project.json file in my .NET Core class library - you can see it is only targeting .NET 4.6 which is what my ASP.NET app is targeting too.

.NET Core Library - Middleware Component

I feel I need some serious .NET 101 course to get my head around how all these dependencies fit together, but if anyone is kind enough to point me in the right direction it would be appreciated.

Community
  • 1
  • 1
jcaddy
  • 501
  • 4
  • 17
  • "My head is spinning with dependencies and frameworks"... ain't that the truth? Microsoft needs to do a seriously good write-up on all this stuff. – Tim Long Jun 18 '16 at 16:20

1 Answers1

7

Remove the reference to NETStandard.Library and it should work. You don't need that if you're only targeting .NET 4.5+.

I work on an OWIN middleware library that can be consumed from both .NET 4.5+ and .NET Core. I target both using a project.json that looks like this:

"dependencies": {
  "Stormpath.Owin.Abstractions": {
    "target": "project",
    "version": "1.0.0"
  }
},
"frameworks": {
  "net45": {
    "frameworkAssemblies": {
      "System.Collections": "4.0.0.0"
    }
  },
  "netstandard1.3": {
    "dependencies": {
      "NETStandard.Library": "1.5.0-rc2-24027"
    }
  }
}

Since only .NET Core (netstandardX.Y) requires .NETStandard.Library, it's listed as a dependency for only that target, not as a general dependency. The project will happily build for .NET 4.5 and dotnet pack produces libraries that install perfectly on both platforms.

Nate Barbettini
  • 51,256
  • 26
  • 134
  • 147
  • 1
    Thanks, Nate - that fixed it for me. I think since I based my .NET Core Class Library off the VS2015 template it assumed I was targeting .NET Core - and hence puts it in as a general dependency. I did as you suggested and it compiles fine - just means I have to work out what other dependencies are required and then add them in explicitly into the target framework. Thanks for your help. – jcaddy Jun 17 '16 at 12:02