produce nuget package on build

Topics: General
Nov 12, 2014 at 12:24 AM
In our SDK we are shipping we have a project template that produces a nuget package on build. To accomplish this we take a dependency on the Nuget.CommandLine package and have this line in the csproj file

<PostBuildEvent>if exist Diagnostic.nuspec if exist "$(SolutionDir)\packages\NuGet.CommandLine.2.8.3\tools\NuGet.exe" "$(SolutionDir)\packages\NuGet.CommandLine.2.8.3\tools\NuGet.exe" pack Diagnostic.nuspec -OutputDirectory .</PostBuildEvent>

Downsides to this approach are
• If the user updates the version of NuGet package then it will silently no longer build
• If the user renames Diagnostic.nuspec then it will silently no longer build
• If the user removes NuGet.CommandLine package then it will silently no longer build

We can remove the if-clauses so the user get a build error in these cases, but I was wondering if there is any supported way to produce a nuget package on build?
Nov 12, 2014 at 2:31 PM
Take a lake a look at the NuGet.targets file that comes with the NuGet.build package: it comes with a built-in "BuildPackage" target.

Also see this post: http://ihadthisideaonce.com/2014/02/24/nuget-like-a-pro-the-msbuild-way/

Unfortunately I don't think using NuGet.targets for building packages gets much love; it isn't super flexible and seems to be missing some features. For instance, no "Clean" target. I even went so far as to make some code changes to improve things a bit, but nobody seems interested in them (see this thread: https://nuget.codeplex.com/discussions/569183).