c# - Referencing .NET 4.6.2 class library from .NET Core app -


i'm using vs update 3 (14.0.25425.01). here's i've done:

  1. create asp.net core web application (.net core)
  2. create class library .net 4.6.2
  3. add net462 frameworks, netcoreapp1.0, imports in project.json
  4. right click on asp.net core app, click add reference, select projects, select class library created in step 2.

i no errors on restoring , reference added asp.net core app. however, cannot access it. cannot add using import declaration or access objects. i've ran through many things nothing seems work , posts versioned fragmented.

enter image description here

here program.cs in asp.net core app. enter image description here

enter image description here

update did nate suggested. thought tried already..but sure enough can access 4.6.2 libraries. however, i'm getting compile errors.

enter image description here

this work in visual studio 2015 update 3, project.json isn't quite right.

instead of adding net462 imports section, should in frameworks section:

"frameworks": {   "net461": { },   "netcoreapp1.0": {     "dependencies": {       "microsoft.netcore.app": {         "type": "platform",         "version": "1.0.0"       }     }   } } 

notice microsoft.netcore.app dependency needs moved netcoreapp1.0 section. that's because dependency required when compiling .net core application.

the reference .net 4.6.2 library part of dependencies section:

"dependencies": {   (...)   "microsoft.extensions.options.configurationextensions": "1.0.0",   "mylibrary": {     "target": "project"   } } 

by structuring way, able reference , use classes in .net 4.6.2 library without problems.


for reference, here's entire working project.json used:

{   "dependencies": {     "microsoft.aspnetcore.mvc": "1.0.0",     "microsoft.aspnetcore.server.iisintegration": "1.0.0",     "microsoft.aspnetcore.server.kestrel": "1.0.0",     "microsoft.extensions.configuration.environmentvariables": "1.0.0",     "microsoft.extensions.configuration.fileextensions": "1.0.0",     "microsoft.extensions.configuration.json": "1.0.0",     "microsoft.extensions.configuration.commandline": "1.0.0",     "microsoft.extensions.logging": "1.0.0",     "microsoft.extensions.logging.console": "1.0.0",     "microsoft.extensions.logging.debug": "1.0.0",     "microsoft.extensions.options.configurationextensions": "1.0.0",     "mylibrary": {       "target": "project"     }   },   "frameworks": {     "net461": { },     "netcoreapp1.0": {       "dependencies": {         "microsoft.netcore.app": {           "type": "platform",           "version": "1.0.0"         }       }     }   },   "version": "1.0.0-*" } 

Comments