Last active
October 25, 2019 18:59
-
-
Save Fireforge/d862e7e6756bcaf9d927 to your computer and use it in GitHub Desktop.
Nuget Package push Powershell script with debug/release specific files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# push_replace.ps1 | |
# | |
# This script is designed to produce customized release and debug nupkgs from a Visual Studio C# project. This is especially useful | |
# for nupkgs that include native DLLs that are different depending upon debug or release mode. | |
# | |
# How to use: | |
# In your .nuspec file in the <files> section, add the following line: | |
# <file src="$filelist$" target="lib\native" /> | |
# That line is set to go to lib\native because this script was made for handling native DLLs, but that target can be anything. | |
# | |
# This script will look for a `debug.txt` and `release.txt` file which is just a list of files you want to include for that | |
# configuration. The file lists must: | |
# - Have only one file per line | |
# - Each file path must end with a semicolon before the end of the line EXCEPT the last one in the file | |
# - The paths must be relative to this script file | |
#### Setup #### | |
Set-Location -Path $PSScriptRoot | |
# project parameters | |
$projname = "MyProject" | |
$nuspec = $projname + ".nuspec" | |
$nuspecBAK = $nuspec + ".TMP" | |
$pushdir = "path\to\release\nupkgs" | |
$debugdir = "path\to\debug\nupkgs" | |
$symdir = "path\to\symbols\nupkgs" | |
#### Debug #### | |
# make sure we're working with a clean directory | |
rm *.nupkg | |
copy $nuspec $nuspecBAK | |
# Generate the debug nuspec file from the base and the file lists | |
$debug_files = Get-Content debug.txt | |
(Get-Content $nuspecBAK).replace('$filelist$', $debug_files) | Set-Content $nuspec | |
# Create the nuget packages, both a default and symbols version | |
nuget pack $PSScriptRoot\$projname.csproj -Build -Symbols -Properties Configuration=Debug | |
# Push the symbols version | |
$symnupkg = ls *.symbols.nupkg | |
nuget push -source $symdir $symnupkg | |
rm $symnupkg | |
# Push the default version | |
$nupkg = ls *.nupkg | |
nuget push -source $debugdir $nupkg | |
rm $nupkg | |
#### Release #### | |
# Generate the release nuspec file from the base and the file lists | |
$release_files = Get-Content release.txt | |
(Get-Content $nuspecBAK).replace('$filelist$', $release_files) | Set-Content $nuspec | |
# Create the nuget package | |
nuget pack $PSScriptRoot\$projname.csproj -Build -Properties Configuration=Release | |
# Push the package | |
$nupkg = ls *.nupkg | |
nuget push -source $pushdir $nupkg | |
rm $nupkg | |
#### Teardown #### | |
copy $nuspecBAK $nuspec | |
rm $nuspecBAK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment