Sunday, August 28, 2016

Why can't my Core 1 library be seen in my ASP.NET Core 1.0 (MVC6) project?

Leave a Comment

I have a little class library (Core 1), separate so that other apps may also use it, and all those reasons. It has only POCO model classes and a DbContext derivative. Its project file looks as follows:

{     "version": "1.0.0-*",     "dependencies": {         "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",         "NETStandard.Library": "1.5.0-rc2-24027",         "System.ComponentModel.Annotations": "4.1.0"     },     "frameworks": {         "netstandard1.5": {             "imports": "dnxcore50"         }     } } 

Then I have an ASP.NET Core Web Application (.NET Core) that I wish to use the class library in. Nearly everywhere I look, and I've looked, says to just add the library to the main project's dependencies section of its project file. There it is, right at the top:

"dependencies": {     "WideWorld.Filing": "1.0.0.0",     "Microsoft.NETCore.App": {         "version": "1.0.0-rc2-3002702",         "type": "platform"     },     "Microsoft.ApplicationInsights.AspNetCore": "1.0.0-rc2-final", 

I can't even see the library namespace WideWorld.Filing in the main project, where I can, obviously, see its namespace, WideWorld.Office. I am very, very new to Core 1, and have only build monolith web applications before, so please excuse my ignorance if I'm missing something obvious.

If I do a package restore on the main project, I get three warnings in the log (and other stuff that looks harmless):

warn : Detected package downgrade: Microsoft.EntityFrameworkCore.SqlServer from 1.0.0 to 1.0.0-rc2-final  warn :  WideWorld.Office (>= 1.0.0) -> WideWorld.Filing (>= 1.0.0) -> Microsoft.EntityFrameworkCore.SqlServer (>= 1.0.0)  warn :  WideWorld.Office (>= 1.0.0) -> Microsoft.EntityFrameworkCore.SqlServer (>= 1.0.0-rc2-final) 

1 Answers

Answers 1

The issue is that you're mixing packages versions. For example the RTM and RC2 packages are not compatible. You should either target everything as RC2 (which I'd advise against) or take the more preferred approach and upgrade all package references to RTM, targeting version 1.0.0.

More details here:

Note, I have omitted the "import": "dnxcore50"

{     "version": "1.0.0-*",     "dependencies": {         "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",         "NETStandard.Library": "1.6.0",         "System.ComponentModel.Annotations": "4.1.0"     },     "frameworks": {         "netstandard1.5": { }     } } 

Likewise, in the other project.json do this:

"dependencies": {     "WideWorld.Filing": "1.0.0.0",     "Microsoft.NETCore.App": {         "version": "1.0.0",         "type": "platform"     },     "Microsoft.ApplicationInsights.AspNetCore": "1.0.0" 

Additional details on packages.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment