Saltar al pie de página
.NET AYUDA
¿Qué es NuGet (Cómo Funciona Para Desarrolladores Tutorial)

¿Qué es NuGet?

A system that allows developers to write, exchange, and use functional code is a crucial component of any modern development platform. This functional code is bundled in "packages" that also include other materials required by the projects that use them, such as compiled code (in the form of DLLs).

The Microsoft-supported method of code sharing for .NET (including .NET Core) is NuGet. NuGet enables the production, hosting, and retrieval of packages for .NET Frameworks. Software packages that NuGet manages are called NuGet packages.

What is NuGet? A NuGet package is just a zip file with the extension .nupkg. It contains all the DLLs required to make the software function. It also contains a descriptive manifest that lists the package's version number, among other things. Developers just need to install the NuGet package, and they can use the methods provided by that package.

NuGet Features

  • NuGet adds private hosting support to the central nuget.org repository.
  • NuGet provides the tools that developers need to create, publish, and install packages.
  • NuGet keeps track of the packages used in a project and allows you to restore and update those packages from that list.
  • NuGet keeps track of all the specifications pertaining to how packages are structured, such as localization and how they are referenced.
  • NuGet provides numerous APIs for programmatically interacting with all of its services, as well as support for developers who publish Visual Studio extensions.
  • NuGet includes a package cache and a global folder for packages to make installation and reinstallation easier. If a package is already present on the local machine, the cache will not download it from the central repository, and will instead serve the package from the cache.

How NuGet Package Works

NuGet, as a public host, maintains a central repository of over 100,000 unique packages. Every day, millions of .NET/.NET Core developers use these packages. NuGet also lets you host packages privately in the cloud (for example, on Azure DevOps), on a private network, or even on your local file system. As a result, those packages are only available to developers who have access to the host, allowing you to make packages available to a specific group of consumers.

A host, whatever its nature, serves as the link between package creators and package consumers. Creators develop useful NuGet packages and distribute them to a host. Consumers then search accessible hosts for useful and compatible packages, downloading and including those packages in their projects. Once installed in a project, the APIs of the packages are accessible to the rest of the project code.

What is NuGet, Figure 1

NuGet Tools

There are six tools which are used to manage NuGet Packages.

.NET CLI

It is a command-line interface (CLI) for .NET Core and .NET Standard libraries, as well as for SDK-style projects targeting the .NET Framework (see SDK attribute). Certain NuGet CLI capabilities are available directly within the .NET Core tool chain. The .NET CLI, like the nuget.exe CLI, does not interact with Visual Studio projects.

NuGet.exe CLI

It is a CLI for .NET Framework libraries and non-SDK-style projects aiming at .NET Standard libraries. It provides all the capabilities of the .NET CLI, with some commands only applicable to package creators and other commands only to consumers. Package creators, for example, use the NuGet pack command to generate a package from various assemblies and related files. Package users use NuGet install to include packages in a project folder. Both package developers and package users use NuGet config to set NuGet configuration variables.

The NuGet CLI does not interact with Visual Studio projects because it is a platform-agnostic tool.

Package Manager Console

The Package Manager Console provides PowerShell commands for installing and managing packages within Visual Studio projects.

Package Manager UI

The Package Manager UI provides a user-friendly interface for installing and managing packages for projects within Visual Studio.

Manage NuGet Package Manager UI

This tool also provides a user-friendly interface for installing and managing packages in projects in Visual Studio. This tool is available only for Mac users.

MSBuild

MSBuild allows users to create and restore packages used in a project directly from the MSBuild tool chain.

Package Manager UI and Package Manager Console are most widely used tools for managing NuGet packages. We will now explore how they are used.

Use of the NuGet Package Manager UI

In Visual Studio, click on Tools from the Top Menu Bar and select NuGet Package Manager > Manage NuGet package for Solutions.

A new window will appear as shown below.

What is NuGet, Figure 2

In the Installed tab, all the NuGet packages that are already installed will appear here.

Click on the Browse Button and write the name of a package in the Search Bar. We will search for IronBarcode as an example.

What is NuGet, Figure 3

Click on the Install Button, the library will be installed and made ready for use.

IronBarcode NuGet Package Details is a library developed and maintained by Iron Software that helps C# software engineers read and write barcodes and QR codes in .NET applications.

Core features include:

  • Read single or multiple barcodes and QR codes from images or PDFs.
  • Image correction for skewing, orientation, noise, low resolution, contrast, etc.
  • Create barcodes and apply them to images or PDF documents.
  • Embed barcodes into HTML documents.
  • Style barcodes and add annotation text.
  • QR Code Writing allows adding of logos, colors, and advanced QR alignment.

Learn more about IronBarcode from the product documentation page.

Use of the Package Manager Console

In Visual Studio, click on Tools from the Top Menu Bar and select NuGet Package Manager => Package Manager console.

The Package Manager Console window will appear as shown below.

What is NuGet, Figure 4

Let's install a package using the Package Manager Console.

The Install-Package 'package-Name' command is used to install the package. For example, to install the IronOCR package:

Install-Package IronPdf

Explore IronOCR NuGet Package is a C# software library that allows .NET software developers to detect and read text from images and PDF documents. It uses the most advanced Tesseract engine known anywhere. IronOCR shines above all other OCR libraries when working with real-world images riddled with imperfections (i.e., digital noise, low-quality resolutions, etc.). It supports multiple programming languages.

Read more technical documentation about IronOCR from the product website.

Some Useful NuGet Packages

This section will describe some useful NuGet Packages available for working with databases and files.

Entity Framework

Discover Entity Framework NuGet Package is the most common and powerful NuGet Package available for working with databases in .NET applications.

It is a Microsoft-supported open-source ORM framework that allows developers to work with data using domain-specific objects rather than using the underlying database tables and columns where the data is stored. When working with data, developers can work at a higher level of abstraction. This allows them to create and maintain data-oriented applications with less code than traditional applications.

There are separate NuGet packages available for managing SQL server, Oracle, MySQL, and PostgreSQL database servers.

The Getting-Started Guide for Entity Framework provides more information about Entity Framework's capabilities.

IronPDF

IronPDF NuGet Package solves the difficult problem of adding PDF processing capabilities to apps. IronPDF automates the conversion of formatted documents to PDF and also allows developers to create, edit, and export PDF documents.

The main features of IronPDF include:

  • Convert web forms, local HTML pages, and other web pages to PDF with .NET.
  • Allow users to download documents, send them by email, or store them in the cloud.
  • Produce invoices, quotes, reports, contracts, and other documents.
  • Work with ASP .NET, ASP .NET Core, web forms, MVC, Web APIs on .NET Framework, and .NET Core.

Read more about IronPDF on its product documentation page.

IronXL

IronXL NuGet Package helps C# software engineers read, create, and edit spreadsheet files in .NET applications. IronXL works well without the use of Office Excel Interop, and does not require additional dependencies or the need to install Microsoft Office.

You can learn more about IronXL from the comprehensive product documentation.

Iron Software provides all five libraries (IronPDF, IronXL, IronBarcode, IronWebScraper, and IronOCR) in a single .NET Suite. You can get all five libraries for the price of two when purchasing the complete suite. All purchases include lifetime product support.

Summary

NuGet is the package manager for .NET applications. The NuGet client tools provide the ability to create, share, and retrieve packages. The NuGet Gallery is the central package repository used by all package authors and consumers.

  • NuGet provides the central nuget.org repository with support for private hosting.
  • NuGet provides the tools developers need for creating, publishing, and installing packages.
  • NuGet maintains a reference of packages used in a project and the ability to restore and update those packages from that list.

Preguntas Frecuentes

¿Cómo puedo convertir HTML a PDF en C#?

Puede utilizar el método RenderHtmlAsPdf de IronPDF para convertir cadenas HTML en PDFs. También puede convertir archivos HTML en PDFs utilizando el método RenderHtmlFileAsPdf.

¿Qué es NuGet y por qué es importante para los desarrolladores .NET?

NuGet es un sistema de gestión de paquetes que permite a los desarrolladores .NET crear, compartir y utilizar código empaquetado de manera eficiente. Simplifica la gestión de bibliotecas y dependencias de terceros, asegurando el uso de las versiones correctas y facilitando la actualización y restauración de paquetes.

¿Cómo instalo un paquete NuGet usando la CLI de .NET?

Para instalar un paquete NuGet usando la CLI de .NET, puede usar el comando dotnet add package [PackageName]. Este comando añade el paquete especificado a su proyecto, agilizando el proceso de gestión de paquetes.

¿Qué herramientas son esenciales para gestionar paquetes NuGet en Visual Studio?

Las herramientas esenciales para gestionar paquetes NuGet en Visual Studio incluyen la interfaz del Gestor de Paquetes, la Consola del Gestor de Paquetes y la CLI de .NET. Estas herramientas permiten la navegación eficiente, instalación y actualización de paquetes dentro de sus proyectos.

¿Cuáles son los beneficios de utilizar alojamiento privado para paquetes NuGet?

El alojamiento privado para paquetes NuGet permite a los desarrolladores compartir paquetes dentro de grupos específicos u organizaciones de manera segura. Esto asegura que solo los usuarios autorizados tengan acceso a ciertos paquetes, mejorando la seguridad y el control sobre la distribución de código.

¿Cómo facilita la Consola del Gestor de Paquetes NuGet la gestión de paquetes?

La Consola del Gestor de Paquetes NuGet en Visual Studio permite a los desarrolladores ejecutar comandos para instalar, actualizar y gestionar paquetes directamente dentro de su entorno de desarrollo. Esto proporciona una interfaz poderosa para manejar dependencias y versiones de paquetes de manera eficiente.

¿Qué papel juega un manifiesto en un paquete NuGet?

Un manifiesto en un paquete NuGet contiene metadatos, como el número de versión del paquete y otra información importante. Estos metadatos son cruciales para identificar, gestionar y resolver dependencias dentro de un proyecto.

¿Puede NuGet ser usado para proyectos que no sean .NET?

Aunque NuGet está diseñado principalmente para proyectos .NET, su infraestructura puede soportar la gestión de paquetes para una variedad de otros proyectos. Sin embargo, su potencial completo y sus características se aprovechan mejor dentro del ecosistema .NET.

¿Cómo simplifican los mecanismos de caché de NuGet la gestión de paquetes?

Los mecanismos de caché de NuGet permiten una fácil instalación y reinstalación de paquetes almacenando los datos de los paquetes localmente. Esto reduce la necesidad de descargar repetidamente paquetes del repositorio central, acelerando el proceso de desarrollo.

¿Cuáles son algunos ejemplos de paquetes NuGet populares?

Paquetes NuGet populares incluyen Entity Framework para interacciones con bases de datos, IronPDF para procesamiento de PDF e IronXL para manipulación de hojas de cálculo. Estos paquetes proporcionan a los desarrolladores herramientas poderosas para mejorar sus aplicaciones .NET.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más