Reputation: 5894
I've started using powershell yesterday and am amazed by how easy it is compared to batch. I was able to resolve most issues with a little bit of search on google, but in this particular case i just don't get any error messages to work with.
This is the script in question:
https://github.com/taori/AjaxHub/blob/master/build/executePackaging.ps1
$apiKey = [IO.File]::ReadAllText("publish.apiKey.txt")
foreach ($package in $packages){
[xml]$xml = Get-Content($package + ".nuspec")
$version = $xml.package.metadata.version;
"Setting up packacking for $package $version"
$packagePath = ".\packages\$package\$version";
If(Test-Path $packagePath){
Remove-Item -Recurse -Force $packagePath
}
md -Force $packagePath
$packArguments = "pack -Symbols -Version $version $package.nuspec -OutputDirectory $packagePath";
"Packaging with Nuget.exe $packArguments"
Start-Process -FilePath ".\Nuget.exe" -WindowStyle Hidden -ArgumentList $packArguments -ErrorAction Stop
$pushArguments = "push $packagePath\$package.$version.symbols.nupkg $apiKey"
"Pushing with Nuget.exe $pushArguments"
Start-Process -FilePath ".\Nuget.exe" -WindowStyle Hidden -ArgumentList $pushArguments -ErrorAction Stop
Start-Process -FilePath "https://www.nuget.org/packages/$package"
}
Read-Host -Prompt "Script done. Press <enter>"
It's only the push part which does not work (at least there's no update on nuget.org) or produces any errors. Does anyone know how to make it work or throw errors i can work with?
Upvotes: 1
Views: 824
Reputation: 5894
Turns out there were multiple issues with my push attempt. I'm not sure why i didn't get any errors with an ordinary call but this helped me display them:
Invoke-Expression "$nugetPath $pushArguments" -ErrorVariable $pushOutput
"pushOutput: $pushOutput";
There are plenty of methods to try capture errors from a cli call but this one seems to be the easiest (and seems to work with asynchronous call errors). Unfortunately Mr Tree's suggestion did not work. I also tried versions with "2>&1", but that only pointed out syntax errors/returned nothing.
The issues i've had were the following:
Script state without errors:
$packages = @("AjaxHub.Core","AjaxHub.MVC5")
$apiKey = [IO.File]::ReadAllText("publish.apiKey.txt")
$nugetPath = ".\Nuget.exe";
Resolve-DnsName "www.nuget.org" -ErrorAction Stop | Out-Null
Resolve-DnsName "www.symbolsource.org" -ErrorAction Stop | Out-Null
foreach ($package in $packages){
[xml]$xml = Get-Content($package + ".nuspec")
$version = $xml.package.metadata.version;
"Setting up packacking for $package $version"
$packagePath = ".\packages\$package\$version";
If(Test-Path $packagePath){
Remove-Item -Recurse -Force $packagePath
}
md -Force $packagePath | Out-Null
# todo add sources for -Symbols pack process
#$packArguments = "pack -Symbols -Version $version $package.nuspec -OutputDirectory $packagePath";
$packArguments = "pack -Version $version $package.nuspec -OutputDirectory $packagePath";
"Packaging with Nuget.exe $packArguments"
Start-Process -FilePath $nugetPath -WindowStyle Hidden -ArgumentList $packArguments -ErrorAction Stop -Wait
$pushArguments = "push $packagePath\$package.$version.nupkg -ApiKey $apiKey -Timeout 60 -Verbosity normal"
"Pushing with Nuget.exe $pushArguments"
Start-Process -FilePath $nugetPath -WindowStyle Hidden -ArgumentList $pushArguments -ErrorAction Stop -Wait
Start-Process -FilePath "https://www.nuget.org/packages/$package"
"";
"";
}
Read-Host -Prompt "Script done. Press <enter>"
Upvotes: 1