简体   繁体   中英

How do I reference a Visual Studio Shared Project in a .NET Core Class Library

I have created a number of Shared Projects and am testing whether these can be shared among all the different project types as I hope and expect. I've managed all of them so far (sometimes with a little workaround), but I can't yet figure out how to do it with a .NET Core Class Library, which would be really useful.

As I can't seem to do it through Visual Studio 2015, does anyone know a way to do it? Perhaps by typing the reference straight into the project.json file for the Class Library?

EDIT: As of Visual Studio 2017 RC, Shared Projects properly work with .NET Core projects.

从Visual Studio 2017 RC开始,共享项目也适用于.NET Core平台。

It seems like this isn't possible - I've been trying to find out how to do it today! The best that I've found comes from this SO question:

How can I use xproj (asp.net/dotnet core project) with shproj (shared project)?

What I'm taking away from it is that I can create Shared Projects that can be referenced directly by NET45/46 class libraries but which will have to be pulled into .NET Core projects using a project.json-based workaround, by adding the following "buildOptions" -

"buildOptions": {
  "compile": {
    "include": [
      "../../TesterShared/**/*.cs"
    ]
  }
}

In the example above, my shared project is called "TesterShared" and Visual Studio has created that in the root of the solution - unlike the .NET Core projects which it creates within a "src" folder (hence the double "../" parent path navigation).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM