How to Create and Use Local NuGet Package in Dot Net

NuGet

NuGet is the package manager for .NET Developers who can create, share and consume essential dot net libraries. NuGet client tools provide the ability to produce and consume these libraries as packages. Moreover, the package increases the code reusability.

Create a class library

First of all, take a class library project.

Library project.

Create a package

Open the Visual Studio developer window or go to the release/debug directory and open the command prompt. Execute the below command to generate a nuget package. Like

dotnet pack -o [output path]

Command prompt

Create a local source alias

Execute the below command to generate a Nuget package local source alias. Like

dotnet nuget add source [Package Source] -n [Package-Source-Alias]

 Nuget pacakge

Use the local nuget package in the project

Create a new project or Open an existing project. Open the Package Manager Console window and execute the below command. Like

dotnet add package [Package Name]

Use Local

Output

Run the project and get the result from the local Nuget package according to your use.

Output

Update packages by version

After changing the class library, you have to need to update your existing local package. So, Open the Visual Studio developer window and execute the below command to update the old Nuget package. Like

dotnet pack -p:[PackageVersion] -o [output path]

Version

Use the updated local nuget package in the project

Open the .csproj file and replace the package version number. Like

 Packge version number

Now, rebuild the project and get an updated package.

Conclusion

Hope this article has helped you to understand about local Nuget package. Here I have tried to explain very simply how to create and use a local Nuget package. Happy coding and thanks for reading my article!