Richard
Richard

Reputation: 654

How do I reference a local class library project in .NET Core 1.1?

I've just started developing with .NET Core 1.1, and I am struggling to see how I can reference a secondary project (e.g. my application's domain/model project) in my primary API project. In previous .NET versions I would have created a class library and referenced it in Visual Studio in the usual way, but I can't seem to see how you could do this in the new framework.

Upvotes: 2

Views: 4590

Answers (3)

Italo José
Italo José

Reputation: 1686

Using CLI(Command Line Interface) write that command :

dotnet add "Current/Project/Path/MyProject.csproj" reference "Other/Project/Path/TheOtherProject.csproj"

Upvotes: 5

Deilan
Deilan

Reputation: 4886

If your primary project is xproj, then it's project.json file should look like that:

{
  // ...

  "dependencies": {
    // ...        
    "SecondaryProjectName": {
      "target": "project"
    }
  },

  // ...
}

Upvotes: 1

Tseng
Tseng

Reputation: 64307

If you are using Visual Studio 2015, you have to create a package from your class library and put it into a folder which you include as nuget feed to your project the add a dependency in project.json to it.

If both are in the same solution, the same applies, but you don't need to manually create a package and set a folder als nuget feed.

If you are using Visual Studio 2017, you can do it same way you did with legacy ASP.NET Applications: Right click the references section, add, browse to the dll and select it. This only works with 2017 and the new VS tooling which uses csproj files instead of xproj ones.

Upvotes: 1

Related Questions