我昨天开始使用PowerShell,并且惊讶于它与批处理相比有多容易。我能够通过google上的一些搜索来解决大多数问题,但在这种特殊情况下,我只是没有收到任何错误消息。
这是有问题的剧本:
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>"
它只是推动部分不起作用(至少在nuget.org上没有更新)或产生任何错误。有谁知道如何使它工作或抛出我可以使用的错误?
答案 0 :(得分:1)
原来我的推送尝试存在多个问题。我不确定为什么我没有通过普通电话收到任何错误,但这有助于我展示它们:
Invoke-Expression "$nugetPath $pushArguments" -ErrorVariable $pushOutput
"pushOutput: $pushOutput";
有很多方法可以尝试从cli调用中捕获错误,但这个方法似乎最简单(并且似乎与异步调用错误一起使用)。不幸的是树先生的建议没有用。我还尝试了使用&#34; 2&gt;&amp; 1&#34;的版本,但是只指出了语法错误/什么都没有返回。
我遇到的问题如下:
脚本状态没有错误:
$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>"