"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > C# | Create Nuget Package using .NET Standard

C# | Create Nuget Package using .NET Standard

Published on 2024-08-07
Browse:206

C# | Create Nuget Package using .NET Standard

Note
You can check other posts on my personal website: https://hbolajraf.net

Tools and technologies used

  • Visual Studio 2022
  • .NET Standard 2.1
  • Nuget.exe

Implementation

New Project Creation

Under Visual Studio create a new Project Class Library and use .NET Standard 2.1 as target framework due to compatibility reason with latests versions of .NET CORE Frameworks.

Use Nuget CLI to generate files

1.Download Nuget.exe file
Use the following link to download the latests version of Nuget.exe file.

2.Generate nuspec file
Under the new project folder created befor, open a cmd console and run the comand bellow in order to generate the nuspec file.

nuget spec NewProjectName.csproj

The result of the command should generate a new file which has the content below :

$id$$version$$title$$author$falseMIThttp://project_url_here_or_delete_this_line/$description$Summary of changes made in this release of the package.$copyright$Tag1 Tag2

3.Generate nupkg file

You have two solutions order to generate the nuget package file(nupkg)

using the post-build event of the project

Under Visual Studio right click on the NewProjectName.crproj and select post-build event tab.
After that put the command bellow and Build the solution

nuget pack "$(ProjectPath)" -Symbols -Properties Configuration=$(ConfigurationName) -IncludeReferencedProjects -OutputDirectory "C:\Dev\nuget_packages\NewProjectName\"

using the Nuget CLI command

Under the cmd window tape the command bellow in order to generate the nuget package

nuget pack MyProject.csproj -properties Configuration=Release -OutputDirectory "C:\Dev\nuget_packages\NewProjectName\"

In all cases the new nuget package file will be generated under the output directory : *C:\Dev\nuget_packages\NewProjectName*

What next ?

Once you've created a package, which is a .nupkg file, you can publish it to the gallery of your choice(Artifactory, Azure artifacts or GitHub Package registry)

Release Statement This article is reproduced at: https://dev.to/hbolajraf/c-create-nuget-package-using-net-standard-9oi If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3