Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Make ASP.Net 5 Reference Normal .Net Class Library that is not in your solution

Earlier I asked this question and got an answer that worked. In order to make your ASP.Net 5 application be able to reference a normal .Net class library that targets the .Net Framework 4.5, you must remove the ' "dnxcore50": { }' reference from your project.json file.

Great. That worked with a simple ClassLibrary project which did nothing.

Now I am trying to do it with more complicated class libraries. Class libraries which reference other NuGet Packages for instance (such as HtmlAgilityPack) and the same technique is not working.

This is very frustrating. I am a little dumbfounded that simply referencing a class library no longer works in the new version of ASP.Net.

One of the "features" that seems to be removed is the ability to reference a compiled DLL for a project that is not in your solution. The "Browse" button is gone from the Add Reference dialog in an ASP.Net 5 project:

enter image description here

Whereas a classic project still has the browse button:

enter image description here

Why? How do I reference a class library that is on my machine, yet I do not want to include in my project?

like image 877
CleverPatrick Avatar asked Mar 16 '23 19:03

CleverPatrick


1 Answers

To reference a DLL on your machine but not in your Solution, you'll need to update the project.json as follows:

{
    "frameworks" : 
    {
        "dnx451" : 
        {
            "bin" : { "assembly": "<path to dll>", "pdb": "<path to pdb if needed>" }
        }
    }
}

Unfortunately, much of the dnx tooling is not yet integrated into VS2015 (the teams are separate, and both are changing too quickly to keep up with each other particularly well), and the Asp.net documentation is still a work in progress.

like image 190
Matt DeKrey Avatar answered Apr 25 '23 23:04

Matt DeKrey