How to reference an external library?

3

I have a project in Asp.Net MVC where I would like to add some new libraries.

They are available for download as .dll , but are also available on Manage NuGet Packages .

What is the best way to add the library to the project by adding dll to some project directory and referencing or installing via NuGet ?

What are the advantages and disadvantages?
What are the risks?

    
asked by anonymous 03.12.2015 / 19:40

2 answers

2

This varies slightly depending on the taste of the project developer (s).

Nuget

When installing a package with nuget, there are some advantages. The main ones are:

  • It's (very) simple to update your libraries.

    Let's say you use the Atlassian SDK library. To update it using simple reference you must download the new DLL, remove the old DLL, and add the new DLL to the project. Now imagine this, this library makes use of another library, the RestSharp , and the staff that makes the Atlassian SDK is using a newer version of the RestSharp. What are you going to have to do? That's right, download the new version of RestSharp, delete the old reference and add the new reference.

    If you are using Nuget, you need to enter this in the Package Manager Console

      

    PM > update-package Atlassian.SDK

    And Nuget will automatically download the new dll, remove the old reference, create the new reference, and update the dependencies. Magical, is not it?

  • You do not need to add binaries to your project.

    Instead of leaving the DLLs of your libraries as part of your project, it creates a packages.config file where it stores the information needed to download the binaries later and creates a /packages folder outside the project scope. This .config file contains all the references of your project. Eg: You have a project on GitHub . This project makes use of 12 libraries, all added by Nuget and you have chosen not to upload the binaries from the libraries to the repository. When someone downloads the project, open it with Visual Studio and build Nuget will download all the libraries referenced in the packages.config file and add them to the project. (For this the Allow Nuget to download missing packages option must be enabled.)

  • The only downside I can see in Nuget is that, maybe , one day this service will be discontinued and you may run out of packages. Or you may run out of upgrading your libraries if the service is temporarily down.

        
    03.12.2015 / 20:06
    5

    If you install the libraries via Nuget Package the references will automatically be created for you; the physical repository of packages will be created outside the scope of the project itself.

    This allows you to share projects, leaving the Nuget Manager job to download the packages present in your project.

    For Assemblies that do not have nuget packages , it's up to you; for organization purposes I generally collect them in a directory in the project named ext .

        
    03.12.2015 / 19:44