Erick T
Erick T

Reputation: 7429

How do I reference a multi-target .NET Core class library from a 4.6.1 project within the same solution?

I am building a set of libraries that will be used by both .NET Core and .NET 4.6.1 projects. I created a new .NET Core class library, and added net461 as a framework. I have verified that the .NET Core library compiles and there are 4.6.1 binaries in the debug folder (along with netstandard1.6).

The .NET Core library and the 4.6.1 application that uses it are located in the same Visual Studio 2015 solution. VS allows me to add a reference to the .NET Core library from the 4.6.1 console application, but any attempts to use the library do not compile. Is this scenario supported in Visual Studio, or do I need package the .NET Core into a nuget package and reference that?

Upvotes: 4

Views: 1273

Answers (1)

Nate Barbettini
Nate Barbettini

Reputation: 53600

Yes, this works fine! If your .NET 4.6.1 application is also using project.json/xproj, then it's as simple as:

"dependencies": {
    "MySharedLibrary": {
        "version": "1.0.0",
        "target": "project"
    }
}

The target: project value tells NuGet to look in the local solution for the library, instead of in your package sources.

If your .NET 4.6.1 application is a .csproj project, you'll have to wait for the future tooling updates in Visual Studio (this isn't supported yet, but it will be). You can work around this by creating a NuGet package from your library (with dotnet pack) and adding it to your project as a normal package - either by hosting on NuGet/MyGet, or your own local feed.

Upvotes: 3

Related Questions