Create a NuGet package from a VS project and include all referenced dependencies

It’s been a while since I had to build a NuGet package, a long while. While as a developer I use multiple NuGet packages all the time in my applications, I think I’ve created only a few of my own. Needless to say, I am a total noob when it comes to building AND publishing NuGet packages.

So the other day the need to do this presented itself, and while building a Nuget package isn’t difficult at all, that said, there are times when you need to do something that isn’t as basic as the multiple examples given on StackOverflow or Microsoft Docs. This was one of those times, I needed to create a NuGet package that will contain just one public method, but to run correctly, it required references to multiple project dependencies.

As I was doing this, I also run into other errors that perhaps someone with experience building NuGet packages wouldn’t ever run into as my problem was that I didn’t know about specific options that you need to include when creating your NuGet package. This is a small post about those two essential command options, and hopefully, when you run into a similar problem, this works as a solution for you too.

If you don’t have the nuget.exe in your computer yet, you can download the latest version from here.

TL;DR;

  1. Open a command window and browse to where your project file is.
  2. nuget spec
  3. nuget pack -Prop Configuration=Release -IncludeReferencedProjects

Continue reading →