How to reference an external library?

Asked

Viewed 1,086 times

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 to dll in some project directory and referencing or installing via Nuget?

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

  • i like to use via Nuget, so when I need to download the project it loads the dependencies automatically. Nuget came to stay!!!!

  • Nuget: What are the advantages? A.: Dependency management automatically. But what about the disadvantages? What are the risks? Are there? Why not use the other method?

2 answers

5

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

This allows you to share projects, leaving it up to Nuget Manager the work of downloading the packages present in your project.

In the case of Assemblies who do not have nuget Packages, is at your discretion; for organization purposes I generally collect them in a directory in the project called ext.

  • Thank you so much for the @Onosendai help, but what would be the benefit in a TFS or GIT environment for example? Is there any risk in either of the two practices in the library removal process?

  • 3

    The benefit would be that you do not store unnecessary binary content in the repository. However, the risk always exists - one day in the future (probably) far away the Nuget service will be discontinued, and you will be without your packages. So it’s always good to take a periodic backup of package Storage.

  • Thank you very much @Onosendai, that’s exactly what I needed to know! If you have more and can fill the answer with your wisdom, rsrsrs...

2


This varies somewhat according to the taste of the developer(s) of the project.

Nuget

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

  1. It’s (very) simple to update your libraries.

    Say you use the library Atlassian SDK. 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 people who make the Atlassian SDK are using a newer version of Restsharp. What will you 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 type this in 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, no?

  2. You don’t need to add binaries to your project.

    Instead of Nuget leaving the dlls of its libraries as part of its project, it creates a file packages.config where it stores the information needed to download the binaries later and creates a folder /packages outside the scope of the project. This file .config contains all references to your project. Ex.: You have a project on Github. This project makes use of 12 libraries, all added by Nuget and you chose not to upgrade the libraries' binaries to the repository. When someone downloads the project, open with Visual Studio and der build Nuget will be in charge of downloading all libraries referenced in the archive packages.config and to add them to the project. (For this purpose the option Allow Nuget to download missing packages must be activated).

The only downside I can see in Nuget is that, maybe, one day this service will be discontinued and you can be without your packages. Or you can stay without updating your libraries if the service is temporarily out of the air.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.