Zum Fußzeileninhalt springen
.NET HILFE
Was ist NuGet (Wie es für Entwickler funktioniert Tutorial)

Was ist 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.

Häufig gestellte Fragen

Wie kann ich HTML in PDF in C# konvertieren?

Sie können die RenderHtmlAsPdf-Methode von IronPDF verwenden, um HTML-Strings in PDFs zu konvertieren. Sie können auch HTML-Dateien in PDFs umwandeln, indem Sie die RenderHtmlFileAsPdf-Methode verwenden.

Was ist NuGet und warum ist es wichtig für .NET-Entwickler?

NuGet ist ein Paketverwaltungssystem, das .NET-Entwicklern ermöglicht, verpackten Code effizient zu erstellen, zu teilen und zu nutzen. Es vereinfacht das Management von Drittanbieter-Bibliotheken und Abhängigkeiten, sorgt dafür, dass die richtigen Versionen verwendet werden, und erleichtert das Aktualisieren und Wiederherstellen von Paketen.

Wie installiere ich ein NuGet-Paket mit der .NET-CLI?

Um ein NuGet-Paket mit der .NET CLI zu installieren, können Sie den Befehl dotnet add package [PackageName] verwenden. Dieser Befehl fügt das angegebene Paket zu Ihrem Projekt hinzu und vereinfacht den Prozess der Paketverwaltung.

Welche Werkzeuge sind unverzichtbar für die Verwaltung von NuGet-Paketen in Visual Studio?

Unverzichtbare Werkzeuge für die Verwaltung von NuGet-Paketen in Visual Studio sind die Paket-Manager-Benutzeroberfläche, die Paket-Manager-Konsole und die .NET CLI. Diese Werkzeuge ermöglichen das effiziente Durchsuchen, Installieren und Aktualisieren von Paketen innerhalb Ihrer Projekte.

Welche Vorteile bietet die Verwendung von privatem Hosting für NuGet-Pakete?

Privates Hosting für NuGet-Pakete ermöglicht es Entwicklern, Pakete sicher innerhalb bestimmter Gruppen oder Organisationen zu teilen. Dies stellt sicher, dass nur autorisierte Benutzer Zugriff auf bestimmte Pakete haben, was die Sicherheit und Kontrolle über die Codeverteilung erhöht.

Wie erleichtert die NuGet-Paket-Manager-Konsole das Paketmanagement?

Die NuGet-Paket-Manager-Konsole in Visual Studio ermöglicht es Entwicklern, Befehle zum Installieren, Aktualisieren und Verwalten von Paketen direkt in ihrer Entwicklungsumgebung auszuführen. Dies bietet eine leistungsstarke Oberfläche für das effiziente Handling von Paketabhängigkeiten und -versionen.

Welche Rolle spielt ein Manifest in einem NuGet-Paket?

Ein Manifest in einem NuGet-Paket enthält Metadaten, wie zum Beispiel die Versionsnummer des Pakets und andere wichtige Informationen. Diese Metadaten sind entscheidend für die Identifizierung, Verwaltung und Lösung von Abhängigkeiten innerhalb eines Projekts.

Kann NuGet für Nicht-.NET-Projekte verwendet werden?

Obwohl NuGet hauptsächlich für .NET-Projekte entwickelt wurde, kann seine Infrastruktur das Paketmanagement für eine Vielzahl anderer Projekte unterstützen. Seine volle Leistungsfähigkeit und Merkmale werden jedoch am besten innerhalb des .NET-Ökosystems genutzt.

Wie vereinfachen Caching-Mechanismen in NuGet das Paketmanagement?

Die Caching-Mechanismen von NuGet ermöglichen eine einfache Installation und Neuinstallation von Paketen, indem sie Paketinhalte lokal speichern. Dies reduziert die Notwendigkeit, Pakete immer wieder aus dem zentralen Repository herunterzuladen, und beschleunigt den Entwicklungsprozess.

Was sind einige Beispiele für beliebte NuGet-Pakete?

Beliebte NuGet-Pakete sind Entity Framework für Datenbankinteraktionen, IronPDF für PDF-Verarbeitung und IronXL für das Bearbeiten von Tabellenkalkulationen. Diese Pakete bieten Entwicklern leistungsstarke Werkzeuge zur Verbesserung ihrer .NET-Anwendungen.

Curtis Chau
Technischer Autor

Curtis Chau hat einen Bachelor-Abschluss in Informatik von der Carleton University und ist spezialisiert auf Frontend-Entwicklung mit Expertise in Node.js, TypeScript, JavaScript und React. Leidenschaftlich widmet er sich der Erstellung intuitiver und ästhetisch ansprechender Benutzerschnittstellen und arbeitet gerne mit modernen Frameworks sowie der Erstellung gut strukturierter, optisch ansprechender ...

Weiterlesen