Using Shared Libraries with .NET Core

孤者浪人 提交于 2021-02-08 15:13:47

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!