Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing Library in ASP.NET Core 1.0 (vNext)

I am learning ASP.NET Core 1.0 (vNext). With that in mind, I have a solution that is structured like this:

MySolution
  src
    MyLibrary
      MyClass.cs
      project.json
    MyWebSite
      Startup.cs
      project.json

I am successfully compiling MyLibrary from the command-line using dnu build. I ran dnu pack which generated MyLibrary.1.0.0.nupkg. There are also two folders: dnx451 and dnxcore50 which both contain MyLibrary.1.0.0.dll. I want to use MyLibrary in MyWebSite, however, I'm confused.

  1. How do I "include" MyLibrary into MyWebSite? Do I manually copy over the .dll file? If so, which one? Should I use the nupkg file instead? This is a private assembly, I do not want to publish it globally via NuGet.
  2. What do I put in MyWebSite/project.json to reference the MyLibrary assembly?
like image 520
Some User Avatar asked Jun 22 '15 16:06

Some User


People also ask

How do I add a reference to .NET Core library?

Add Class Library Reference To use a class library in your application, you must add a reference to the library to access its functionality. Right click on the project name of your console app in Solution Explorer and select Add ->Reference option.

Can .NET Core Reference .NET framework libraries?

The answer is no, we cannot use . NET Framework Base Class Library in . NET Core because of compatibility issues.

What is the difference between ASP.NET Core and .NET Core?

NET Core is a runtime to execute applications build on it. ASP.NET Core is a web framework to build web apps, IoT apps, and mobile backends on the top of . NET Core or . NET Framework.


2 Answers

Are you using Visual Studio 2015 RC? If so then follow these steps:

  1. Expand your web project in the Solution Explorer
  2. Right click on References
  3. Click on Add Reference... from the context menu
  4. Select Projects from the Reference Manager
  5. Tick the checkbox next to MyLibrary
  6. Click OK
  7. Profit

If you are not using visual studio then this can be achieved by updated the project.json file in your web project.

If you created a "vNext class library project" then add this to the dependencies property on the json object:

"dependencies": {
      "MyLibrary": "1.0.0-*"
   }
like image 63
Anish Patel Avatar answered Oct 20 '22 01:10

Anish Patel


You don't have to publish the package to NuGet if you don't want to share it with other people/projects outside of your solution. You can just reference the package directly from source.

However, if that still doesn't work for you then you have three options:

  1. Internalize using Roslyn. Example: project.json and the actual code
  2. You can reference the sources directly. Example project.json
  3. Create a build time dependency. Example project.json and actual code for the package
like image 25
Victor Hurdugaci Avatar answered Oct 20 '22 00:10

Victor Hurdugaci