1
votes

I've been looking everywhere for the best way to automate creation of a NuGet package from a Visual Studio project. This is the latest set of instructions for setting things up, but I'm having trouble following that due to recent changes. I'm looking for setup instructions that include:

  • Which NuGet packages I need to include
    • Nothing I found used these which seems odd to me
    • The descriptions aren't very helpful
  • What changes I need to make to the .csproj file to automate packaging via MSBuild
    • Please include instructions for both .csproj and .nuspec files (if there's differences)
    • Bonus: Package specific files in .nuspec with token replacement from .csproj

I'm using Visual Studio 2015. It'd be nice if the instructions were compatible with 2013 as well, but that's not a deal breaker.

1
@AaronCarlson The bonus—as of today and as far as I'm aware—is impossible. Existing instructions include a Package Restore feature that's nonexistent in my version of Visual Studio. I've tried downloading the NuGet packages, but I can find nothing on how to use them. I can do everything from the command line, so at present I have a post-build event that can do this, but it's presumptuous. - ricksmt
@AaronCarlson Yes. I would like to use the MSBuild targets in the NuGet packages to generate a project's NuGet package. - ricksmt
If you are in VS 2015, then create a .xproj can save you time as it directly generates NuGet package as output. - Lex Li
@LexLi I'm not familiar with .xproj. Can you provide documentation and/or examples? - ricksmt

1 Answers

0
votes

For easy use, here's my NuGet.targets file. The link you posted seems to have the same idea. https://gist.github.com/makhdumi/71e7701b87b69f3cde1d/revisions

I use this with an MSBuild command and it works well, so I'm assuming inside VS2015 should be OK. Either run MSBuild with /p:BuildPackage=true or uncomment this line to always build packages for projects that have .nuspec files:

<!-- <BuildPackage>true</BuildPackage -->

To Push, you'll need a few more parameters:

/p:PublishPackage=true;PackageDestination="https://<your-nuget-site.com>";PackageDestinationApiKey="<your-api-key>"

Steps

  1. Copy over the .nuget folder from a VS2013 solution. This should contain nuget.targets, nuget.exe, and (possibly) nuget.config. Replace nuget.targets with the one linked above.

  2. Modify every .csproj you have to include the .targets file (NuGet in VS2013 automatically does this):

    <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />`