Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction and usage of Nuget

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "Introduction and Use of Nuget". The explanation content in this article is simple and clear, and it is easy to learn and understand. Please follow the ideas of Xiaobian to study and learn "Introduction and Use of Nuget" together.

Nuget Introduction

NuGet is a package manager for. NET (free). NuGet client tools provide the ability to generate and consume software packages. NuGet Gallery is the central package repository used by all package authors and consumers.

In short, nuget packages solve the problem of dll references, which developers can package and publish to public or private hosts for use by other developers. This greatly improves the efficiency of creating a. NET application.

I want to know how the nuget package installed at ordinary times is generated. There are several roles to understand.

Creator: The author of the package, creates a project, and eventually generates a file with the suffix.nupkg, which contains the compiled code DLL, other files related to the code, and description lists such as versions.

Host: nuget.org is a public host that you can choose if you also want to publish a package for all developers to use. NuGet itself is responsible for maintaining a central repository of more than 100,000 unique packages at nuget.org These packages are used by millions of. NET/. Net Core developers every day. On a private host, for example, several people within the team can access it.

Consumers: well understood, developers who we get packages from nuget.

To summarize the relationship between these roles, the creator creates a nuget package and publishes it to the host. The user then searches accessible hosts to install nuget packages into the project so that the project can take advantage of the functionality provided by the package. Fig.

tool selection

The tools currently available are quite rich. Use dotnet CLI below. You can also choose any tool you are used to.

packaged

To get started, create a class library and name it AA.Nlog.

1. Configure package metadata, right-click Item-> Properties

In the.csproj file, we found the following attributes added:

net452;netstandard2.0 Support NLog https://github.com/ChengLab/AAFrameWork git NLog https://github.com/ChengLab/AAFrameWork false

If the Generate Nuget package in version option box is checked, the nuget package will be automatically generated when the project is generated; Package ID: is a unique identifier, and users search and use it through the package ID. Package version: It is automatically generated according to the assembly version. If you want to update the package, you only need to increase the version number. Other information can be filled in by yourself.

2. To generate a nuget package (.nupkg file) from the project, run the pack command as follows:

dotnet pack

nuget package has been generated, what is a nupkg file? The nuspec file is an XML manifest that contains package metadata. This checklist can be used to construct packaging and provide information to consumers. The list is always included in the package. More details about nuspec can be found in Microsoft documentation (https://docs.microsoft.com/en-us/nuget/reference/nuspec)

Publish Package to Public Host Create API Key

Log in to your nuget.org account, or create one if you don't already have one. For more information about creating an account, see Personal accounts.

Select the username (in the upper right corner) and select API Key.

Select Create, provide a key name, select Select Range> Push. Enter Glob Mode * and select Create.

Once the key is created, select Copy to retrieve the access key that needs to be used in CLI:

Publishing nuget packages using dotnet CLI

Run the command, specify the package name (unique package ID) and replace the key value with your API key:

dotnet nuget push AA.NLog.1.0.0.nupkg -k qz2jga8pl3dvn2akksyquwcs9ygggg4exypy3bhxy6w6x6 -s https://api.nuget.org/v3/index.json

Release Process Results

info : Pushing AA.NLog.1.0.0.nupkg to 'https://www.nuget.org/api/v2/package'... info : PUT https://www.nuget.org/api/v2/package/warn : All published packages should have license information specified. Learn more: https://aka.ms/deprecateLicenseUrl.info : Created https://www.nuget.org/api/v2/package/ 2854 ms info : Package pushed. Here-k stands for API key and-s stands for source. In our example, the source is nuget.org

We log in to nuget.org to view our packages:

You can manage it. After publishing, wait a few minutes and search in nuget.org

Browse our nuget packages in vs

Manage nuget packages-> Search for packages we just released, AA.Nlog.

As shown above, the software package is ready for use.

Thank you for reading, the above is the content of "Nuget introduction and use method", after the study of this article, I believe everyone has a deeper understanding of Nuget introduction and use method, the specific use situation still needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report