![NuGet-Logo.wine](https://magoarcade.org/wp-content/uploads/2020/10/NuGet-Logo.wine_-678x381.png)
This will automate a Nuget update to your personal/company NuGet library for any projects you build as “Release” This is useful for any personal/private libraries you maintain. This basically automates the process here:
Directions around how to get this set up are at the top of the script. an example of a NuGet repo URL is: https://mysite.uk/myNuGet/nuget
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
:: NuGet Auto-publish on Build :: by stigzler, MagoArcade.org :: USAGE: First, install nuget.exe and add it to your Environment Path variable (guide here: https://docs.microsoft.com/en-us/nuget/quickstart/create-and-publish-a-package-using-visual-studio-net-framework) :: Save the Script below somewhere in your solution (I save it in a dir in the Solution folder called "BuildScripts") :: Add the below script to your projects Post-Build Events (Project Properties>Compile>Build Events): :: If $(ConfigurationName) == Debug Exit :: $(SolutionDir)\BuildScripts\PushToNuget.bat $(ProjectDir) $(TargetName) :: Whenever you want to publish to NuGet, just build the Release version. :: DO NOT FORGET TO INCREASE THE ASSEMBLY VERSION ON ANY NEW PUBLISHING, else you will get a conflict error. :: Consider implementing a Version number auto-increase script in the pre-build events. Try this here: :: https://magoarcade.org/automated-version-control-and-deployment-pre-and-post-build-scripts-for-visual-studio/ :: USER VARIABLES ================================================================= set ApiKey=B3EVYX7uRhzB2NECVHb7ftHHsTF5gIWr set NugetUrl=https://nuget.stig.org.uk/nuget :: Do Not Edit below this line :: ================================================================================ echo ====== PUBLISHING TO NUGET ====== set ProjectDir=%1% set TargetName=%2% cd %ProjectDir% echo Attempting to Pack project.. nuget pack -Prop Configuration=Release -OutputFileNamesWithoutVersion If %ERRORLEVEL% NEQ 0 ( Echo ERROR whilst Packing. Cannot continue. Ending. Goto End ) echo Attempting to Push package... nuget push %TargetName%.nupkg -ApiKey %ApiKey% -Source %NugetUrl% If %ERRORLEVEL% NEQ 0 ( Echo ERROR whilst Pushing package. A 409 is likely your forgetting to update teh Version Number. ) :End echo ====== ENDING NUGET OPERATIONS ====== exit 0 :: =============================================================================== |
Leave a Reply