Click here to Skip to main content
13,201,050 members (53,387 online)
Click here to Skip to main content
Add your own
alternative version

Stats

9.9K views
16 bookmarked
Posted 1 Jun 2017

How to Create a Nuget Package on Each Visual Studio Build with NuPack

, 7 Jun 2017
Rate this:
Please Sign up or sign in to vote.
NuPack is a nuget package used to add a build step to a project in order to pack output into a nuget package.

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:

  1. 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

  2. Console: Pack the console as util and provide a build step through .targets file to call console application with 5 arguments:
    1. $(SolutionPath)
    2. $(ProjectPath)
    3. $(Configuration)
    4. $(PlatformName)
    5. $(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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Puresharper
Architect
France France
After working in electronics, I fall in love with software development which is a real passion for me, particulary architecture concerns for productivity.

You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionWill this work with MSBuild Pin
Dave Moor (the real one)13-Jun-17 9:35
memberDave Moor (the real one)13-Jun-17 9:35 
AnswerRe: Will this work with MSBuild Pin
Puresharper13-Jun-17 10:59
professionalPuresharper13-Jun-17 10:59 
PraiseInteresting tool. Pin
n.podbielski8-Jun-17 9:37
membern.podbielski8-Jun-17 9:37 
GeneralRe: Interesting tool. Pin
Puresharper8-Jun-17 11:09
professionalPuresharper8-Jun-17 11:09 
GeneralRe: Interesting tool. Pin
n.podbielski8-Jun-17 20:27
membern.podbielski8-Jun-17 20:27 
QuestionVS2017 support? Pin
Member 20526146-Jun-17 19:57
memberMember 20526146-Jun-17 19:57 
AnswerRe: VS2017 support? Pin
Puresharper8-Jun-17 0:03
professionalPuresharper8-Jun-17 0:03 
PraiseGreat Tool Pin
shaib.vami3-Jun-17 7:05
membershaib.vami3-Jun-17 7:05 
GeneralMessage Closed Pin
1-Jun-17 20:06
memberMember 132237681-Jun-17 20:06 
NewsRe: My vote of 4 Pin
Paw Jershauge1-Jun-17 21:44
memberPaw Jershauge1-Jun-17 21:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171020.1 | Last Updated 8 Jun 2017
Article Copyright 2017 by Puresharper
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid