Search code examples
visual-studionugetexternal

Difference between adding a Reference and adding a Nuget package to a project in Visual Studio


I have a VS (2015) project. I see there's a "References" section in the Solution Explorer view of my project that includes things like System.Core. I'm assuming these are .dlls that have been added to the project?

I can also right-click on the project file (again in the Solution Explorer) and select the option to "Manage NuGet Packages". I know the NuGet allows me to add external code to my project (e.g. external .dlls and associated files).

What's the difference between adding a reference to my project and adding a .nupkg to my project? Is it just that .nupkg can contain a whole bunch of other things aside from a .dll (e.g. documentation)? Why would I use one or the other?


Solution

  • What's the difference between adding a reference to my project and adding a .nupkg to my project?

    NuGet essentially does not differ from manually adding references, and ultimately adds references to the project. It is a tool that automatically adds assemblies to us and manages them, effectively improving the efficiency of our development projects.

    For more details, you can check the document about nuget:

    Put simply, a NuGet package is a single ZIP file with the .nupkg extension that contains compiled code (DLLs), other files related to that code, and a descriptive manifest that includes information like the package's version number. Developers with code to share create packages and publish them to a public or private host. Package consumers obtain those packages from suitable hosts, add them to their projects, and then call a package's functionality in their project code. NuGet itself then handles all of the intermediate details.

    Because NuGet supports private hosts alongside the public nuget.org host, you can use NuGet packages to share code that's exclusive to an organization or a work group. You can also use NuGet packages as a convenient way to factor your own code for use in nothing but your own projects. In short, a NuGet package is a shareable unit of code, but does not require nor imply any particular means of sharing.

    .

    Is it just that .nupkg can contain a whole bunch of other things aside from a .dll (e.g. documentation)?

    Yes, NuGet package could include specify files in the package.

    Why would I use one or the other?

    Nuget provides several additional benefits:

    • it automatically configures your projects by adding references to the necessary assemblies, creating and adding project files (e.g. configuration), etc.
    • it provides package updates
    • it does all of this very conveniently

    I'm sure that once you use it, you'll realize that it has many benefits.

    Check Why use NuGet for more details.

    Hope this helps.