问题
I wrote my open source library, LINQ to Twitter, with shared libraries to minimize deployment artifacts and handle platform specific features. I want to support .NET Core and am thinking that the fastest approach would be to reference the shared libraries. The Add References dialog didn't show the shared libraries, so I tried project.json:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0",
"LinqToTwitter.Shared": "*",
"LinqToTwitter.Shared.net": "*"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
I tried a few combinations of versions, but didn't get anywhere. The error messages contain something like this:
The dependency LinqToTwitter.Shared >= * could not be resolved.
Next, I opened the *.xproj and pasted the following Imports into the Project section:
<Import Project="..\LinqToTwitter.Shared\LinqToTwitter.Shared.projitems"
Label="Shared" />
<Import
Project="..\LinqToTwitter.Shared.net\LinqToTwitter.Shared.net.projitems"
Label="Shared" />
This doesn't show references in VS, nothing in metadata, and (as it would follow) can't reference any shared library types from a console app that references the .NET core app.
回答1:
if library is in the same solution you can reference it using target:project
something like
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0",
"LinqToTwitter.Shared": {"target": "project"},
"LinqToTwitter.Shared.net": {"target": "project"}
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
回答2:
Good news - Visual Studio 2017 now allows .NET Core library projects to reference Shared projects.
来源:https://stackoverflow.com/questions/38134489/using-shared-libraries-with-net-core