Introduction
Nuget is a good way to distribute libraries and even more, there exist a bunch of UI and command lines to manage nuget package. I used to execute command line to automatically produce nuget package from project or solution but it is limited to most common pattern (library packaging). I often use Nuget Package Explorer to create and update my nuget package because it allows you to manipulate package as per your needs. Unfortunately, it is very non productive to manually edit a nuget package when it is done often. That's why it can be interesting to use a nuget package like NuPack to do the job.
NuPack
NuPack is a nuget package for .NET 4.0+ that adds an additional build step to pack output of project into a nuget package. It is simple to add, use or remove because it is materialized by a single nuget package without any additional task to do.
This nuget package is an open source project and is under MIT Licence that allows you to use it without any restrictions.
Automatic
NuPack automatically creates a nuget package on each build with assembly name as id. It can work with 2 templates:
- Library: Pack a library assembly in lib folder and declare dependencies automatically
Reference NuPack from nuget.org
Define Assembly Attribute to Provide Clean Metadata
NuPack Nuget Package Creation on Build Project
NuPack Nuget Package Creation Observed with Nuget Package Explorer
- Console: Pack the console as util and provide a build step through .targets file to call console application with 5 arguments:
$(SolutionPath)
$(ProjectPath)
$(Configuration)
$(PlatformName)
$(TargetPath)
Automatic Nuget Package from Console Application Observed with Nuget Package Explorer
Manual
NuPack detects .nuspec file when it is part of project and simply respects the specification to create the expected nuget package.
Dependencies
NuPack automatically manages dependencies by including nuget package dependencies and all resources (all files found in output path) into lib folder except files found in nuget dependencies and specific files like .pdb, .bak, .tmp, .vshost.exe.
Example: Use Cases
- When a project references a nuget package, NuPack will include it in package as dependency.
- If a project references another as project reference, NuPack will include output of dependency into package in lib folder.
- If a dependency is a project reference but is a nuget producer (using NuPack ou produce by another way a .nupkg into output), NuPack will include it as nuget dependency.
References
Conclusion
There are many ways to create a package nuget. NuPack is one of them and can be useful in some scenarios. It is easy to use without any effort and can help to keep your nuget package up to date as soon as possible without deploying a white elephant.