简体   繁体   中英

MSBuild NuGet Package

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.

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')" />` 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM