13

I have a solution in Visual Studio with 12 projects. I would like to create a nuget package from Visual Studio, but it appears the "Produce outputs on build" that was there from RC1 is missing.

I can go ahead and create a script that goes to each folder and call "dotnet pack", but is there an option in Visual Studio that I am missing to do this?

Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311
DavidG
  • 469
  • 3
  • 12

2 Answers2

31

Add this to your project.json file:

"scripts": {
  "postcompile": [
    "dotnet pack --no-build --configuration %compile:Configuration%"
  ]
}

This will run the dotnet pack command which will pack your build output produced after compilation into a NuGet package. For more info, see this.

I'm not sure how to only do this in release mode, so I've asked that question here.

UPDATE

Updated the answer based on the other question.

Muhammad Rehan Saeed
  • 35,627
  • 39
  • 202
  • 311
  • I always get "Dependency Could not be resolved" error if I try to add a reference with this nuget package which created with postcompile? Have ever run into any problem like this? Thanks – Barbaros Alp Jun 09 '16 at 10:05
  • If you want to build a NuGet package with release binaries, all you need to do is add the -c / --configuration switch and use release as the argument. [quoted from here](https://learn.microsoft.com/en-us/dotnet/articles/core/deploying/creating-nuget-packages) – csa Oct 05 '16 at 11:53
  • This only packages up the exe, not any of the numerous other dependencies in the bin folder. – The Muffin Man Jan 16 '17 at 02:55
0

At this point, I don't believe there is an option to do this automatically in VS. You can look into using NuProj to do this if you like.