在 .NET Core 中使用共享库 [英] Using Shared Libraries with .NET Core
问题描述
我编写了我的开源库,LINQ to Twitter,使用共享库最大限度地减少部署工件和处理平台特定功能.我想支持 .NET Core 并且我认为最快的方法是引用共享库.添加引用对话框没有显示共享库,所以我尝试了 project.json:
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:
依赖 LinqToTwitter.Shared >= * 无法解析.
The dependency LinqToTwitter.Shared >= * could not be resolved.
接下来,我打开 *.xproj 并将以下导入粘贴到项目部分:
Next, I opened the *.xproj and pasted the following Imports into the Project section:
<Import Project="..LinqToTwitter.SharedLinqToTwitter.Shared.projitems"
Label="Shared" />
<Import
Project="..LinqToTwitter.Shared.netLinqToTwitter.Shared.net.projitems"
Label="Shared" />
这不会在 VS 中显示引用,在元数据中也没有显示任何内容,并且(正如接下来的内容)无法从引用 .NET 核心应用程序的控制台应用程序引用任何共享库类型.
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.
推荐答案
好消息 - Visual Studio 2017 现在允许 .NET Core 库项目引用共享项目.
Good news - Visual Studio 2017 now allows .NET Core library projects to reference Shared projects.
这篇关于在 .NET Core 中使用共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!