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)
One method of adding references to your library is by typing it directly in the project. json file. As you can see that we have added some references under the dependencies section as shown in the following code. Let us now save this file and you will see that references are added to your library now.
The upshot is that you can create libraries that can be directly referenced by . Net Framework, . Net Core and Xamarin applications.
With . NET Core, you can build cross-platform console apps and ASP.NET Core Web applications and cloud services. . NET Standard: This is the set of fundamental APIs (commonly referred to as base class library or BCL) that all .
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With