How to add Project Reference in asp.net 5 application

10.9k views Asked by At

As per my knowledge, Visual Studio 2015 has some update and we can't add DLLs in asp.net 5 application any more, if we need to add then we need to make NuGet package and then install it.

Now my Questions are:-

1) If I have one project with two class libraries then how can i add that class library's reference (DLL) in my asp.net 5 application?

2) If a class library is also in development mode then how to update that DLL in asp.net 5 application if that DLL install via NuGet, because every time for publish on NuGet and get latest take more time.

3) Suppose if we need to add all DLLs using NuGet then what about private DLLs?

4) Is there any way without NuGet package manager to handle this?

4

There are 4 answers

3
Andriy Horen On BEST ANSWER

Quick answer - you don't need NuGet packages for that and yes, it's possible to refer your own libs.

Two ways:

  1. By adding it into root level "dependecies" object in your project.json. Be aware that this action will add reference into every target framework listed in the "frameworks" section, therefore if you adding reference to the old-type class library it would not work with new DNXCore 5.0

    {
       "webroot": "wwwroot",
       "version": "1.0.0-*",
    
       "dependencies": {
           "Library": "1.0.0-*" 
    
  2. By adding it for specific framework version. Which is more flexible as you can use old-type libs for DNX451 and new vNext Class Libraries for DNXCore 5.0

    "frameworks": {
        "dnx451": {
            "dependencies": {
                "ClassicLib": "1.0.0-*",
                "vNextLib": "1.0.0-*",
            }
        },
        "dnxcore50" : {
            "dependencies": {
                "vNextLib": "1.0.0-*"
            }
        }
     } ....
    

All samples I've checked on Visual Studio 2015 RC.

0
StackOverflowUser On

I have edited my previous answer to point you to the following answer on StackOverflow:

Issue adding reference to class library project in ASP.NET 5 (Core)

I can verify the answer there works if your front-end project, the one from which you need to reference other class libraries, is ASP.NET 5 MVC 6 beta6.

0
Benoit On

You need to create a project.json for your assembly. you can use the command :

 kpm wrap "c:\path\to.csproj"

This will create a "wrap" folder in the solution root folder. Then you must be able to add reference to your project. If it don't work, try to move the project.json in the project directory.

To use kpm(K Package Manager), you need to have installed the "k" and "dnx" tools and have a active version installed.

If kpm command don't work, folow this:

1) Open PowerShell as admin and type this command to allow the powershel to download and install the package:

Set-ExecutionPolicy RemoteSigned

2) Open a cmd with admin right and enter the folowing command to install the package:

 @powershell -NoProfile -ExecutionPolicy unrestricted -Command "&{$Branch='dev';iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/aspnet/Home/dev/dnvminstall.ps1'))}"

3) In cmd, you can update and set the environement varriables with the foloing command:

 dnvm upgrade

then try again the "kpm wrap" command

After that, you will be able to add a reference to your project. But i thing it will not work with core. if you have problem, try use an other dnvm version (like beta2 or "2 1.0.0-beta5") with the command dnvm install like this:

dnvm install 1.0.0-beta4-11566
1
watbywbarif On

You can add old class library Foo.csproj to Bar.xproj as reference but not directly, see instructions below. It can be done without uploading packages in Beta8.

  1. Go too Foo.csproj folder, type: dnv wrap Foo.csproj.
  2. You should now have some files generated, for me it was Foo/wrap/Foo/project.json. Go to your solution in Visual Studio, Add -> Existing project -> project.json.
  3. Now you have some more files, including Foo.xproj which is available in Visual Studio solution, but it does not build.
  4. Open cmd in Foo dir and execute dnu restore.
  5. After 4) completes with no error and Foo.xproj can be built you can now go to Bar.xproj and add Foo.xproj as reference.
  6. Open cmd in Bar directory and execute dnu restore.
  7. You can now build Bar.xproj

I really hope that this will be easier in final version.