diff --git a/src/PowerShellGet/private/functions/New-NugetPackage.ps1 b/src/PowerShellGet/private/functions/New-NugetPackage.ps1
index 16cd6502..c4d773ab 100644
--- a/src/PowerShellGet/private/functions/New-NugetPackage.ps1
+++ b/src/PowerShellGet/private/functions/New-NugetPackage.ps1
@@ -19,6 +19,8 @@ function New-NugetPackage {
)
Set-StrictMode -Off
+ Write-Verbose "Calling New-NugetPackage"
+
if (-Not(Test-Path -Path $NuspecPath -PathType Leaf)) {
throw "A nuspec file does not exist at $NuspecPath, provide valid path to a .nuspec"
}
@@ -27,89 +29,96 @@ function New-NugetPackage {
throw "NugetPackageRoot $NugetPackageRoot does not exist"
}
+ $processStartInfo = New-Object System.Diagnostics.ProcessStartInfo
if ($PSCmdlet.ParameterSetName -eq "UseNuget") {
if (-Not(Test-Path -Path $NuGetExePath)) {
throw "Nuget.exe does not exist at $NugetExePath, provide a valid path to nuget.exe"
}
+ $ProcessName = $NugetExePath
$ArgumentList = @("pack")
$ArgumentList += "`"$NuspecPath`""
- $ArgumentList += "-outputdirectory `"$OutputPath`""
-
- $processStartInfo = New-Object System.Diagnostics.ProcessStartInfo
- $processStartInfo.FileName = $NugetExePath
- $processStartInfo.RedirectStandardError = $true
- $processStartInfo.RedirectStandardOutput = $true
- $processStartInfo.UseShellExecute = $false
- $processStartInfo.Arguments = $ArgumentList
-
- $process = New-Object System.Diagnostics.Process
- $process.StartInfo = $processStartInfo
- $process.Start() | Out-Null
- $process.WaitForExit()
-
- if (-Not ($process.ExitCode -eq 0 )) {
- $stdErr = $process.StandardError.ReadToEnd()
- throw "nuget.exe failed to pack $stdErr"
- }
+ $ArgumentList += "-outputdirectory `"$OutputPath`" -noninteractive"
+
+ $tempPath = $null
}
+ else {
+ # use Dotnet CLI
- if ($PSCmdlet.ParameterSetName -eq "UseDotnetCli") {
#perform dotnet pack using a temporary project file.
- $dotnetCliPath = (Get-Command -Name "dotnet").Source
+ $ProcessName = (Get-Command -Name "dotnet").Source
$tempPath = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath ([System.Guid]::NewGuid()).Guid
New-Item -ItemType Directory -Path $tempPath -Force | Out-Null
$CsprojContent = @"
-
-
- NotUsed
- Temp project used for creating nupkg file.
- netcoreapp2.0
- true
-
-
+
+
+ NotUsed
+ Temp project used for creating nupkg file.
+ netcoreapp2.0
+ true
+
+
"@
$projectFile = New-Item -ItemType File -Path $tempPath -Name "Temp.csproj"
Set-Content -Value $CsprojContent -Path $projectFile
- #execution
-
$ArgumentList = @("pack")
$ArgumentList += "`"$projectFile`""
$ArgumentList += "/p:NuspecFile=`"$NuspecPath`""
$ArgumentList += "--output `"$OutputPath`""
+ }
- $processStartInfo = New-Object System.Diagnostics.ProcessStartInfo
- $processStartInfo.FileName = $dotnetCliPath
- $processStartInfo.RedirectStandardError = $true
- $processStartInfo.RedirectStandardOutput = $true
- $processStartInfo.UseShellExecute = $false
- $processStartInfo.Arguments = $ArgumentList
+ # run the packing program
+ $processStartInfo = New-Object System.Diagnostics.ProcessStartInfo
+ $processStartInfo.FileName = $ProcessName
+ $processStartInfo.Arguments = $ArgumentList
+ $processStartInfo.RedirectStandardError = $true
+ $processStartInfo.RedirectStandardOutput = $true
+ $processStartInfo.UseShellExecute = $false
+
+ Write-Verbose "Calling $ProcessName $($ArgumentList -join ' ')"
+ $process = New-Object System.Diagnostics.Process
+ $process.StartInfo = $processStartInfo
+
+ $process.Start() | Out-Null
+
+ # read output incrementally, it'll block if it writes too much
+ $outputLines = @()
+ Write-Verbose "$ProcessName output:"
+ while (! $process.HasExited) {
+ $output = $process.StandardOutput.ReadLine()
+ Write-Verbose "`t$output"
+ $outputLines += $output
+ }
- $process = New-Object System.Diagnostics.Process
- $process.StartInfo = $processStartInfo
- $process.Start() | Out-Null
- $process.WaitForExit()
+ # get any remaining output
+ $process.WaitForExit()
+ $outputLines += $process.StandardOutput.ReadToEnd()
- if (Test-Path -Path $tempPath) {
- Remove-Item -Path $tempPath -Force -Recurse
- }
+ $stdOut = $outputLines -join "`n"
- if (-Not ($process.ExitCode -eq 0 )) {
- $stdOut = $process.StandardOutput.ReadToEnd()
- throw "dotnet cli failed to pack $stdOut"
- }
+ Write-Verbose "finished running $($processStartInfo.FileName) with exit code $($process.ExitCode)"
+
+ if (($tempPath -ne $null) -and (Test-Path -Path $tempPath)) {
+ Remove-Item -Path $tempPath -Force -Recurse
+ }
+ if (-Not ($process.ExitCode -eq 0 )) {
+ # nuget writes errors to stdErr, dotnet writes them to stdOut
+ if ($UseDotnetCli) {
+ $errors = $stdOut
+ }
+ else {
+ $errors = $process.StandardError.ReadToEnd()
+ }
+ throw "$ProcessName failed to pack: error $errors"
}
- $stdOut = $process.StandardOutput.ReadToEnd()
$stdOut -match "Successfully created package '(.*.nupkg)'" | Out-Null
$nupkgFullFile = $matches[1]
- $stdOut = $process.StandardOutput.ReadToEnd()
-
- Write-Verbose -Message $stdOut
+ Write-Verbose "Created Nuget Package $nupkgFullFile"
Write-Output $nupkgFullFile
}
diff --git a/src/PowerShellGet/private/functions/New-NuspecFile.ps1 b/src/PowerShellGet/private/functions/New-NuspecFile.ps1
index e071d20e..1cc17497 100644
--- a/src/PowerShellGet/private/functions/New-NuspecFile.ps1
+++ b/src/PowerShellGet/private/functions/New-NuspecFile.ps1
@@ -49,6 +49,8 @@ function New-NuspecFile {
)
Set-StrictMode -Off
+ Write-Verbose "Calling New-NuspecFile"
+
$nameSpaceUri = "http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"
[xml]$xml = New-Object System.Xml.XmlDocument
diff --git a/src/PowerShellGet/private/functions/Publish-NugetPackage.ps1 b/src/PowerShellGet/private/functions/Publish-NugetPackage.ps1
index d410bd30..d470dba4 100644
--- a/src/PowerShellGet/private/functions/Publish-NugetPackage.ps1
+++ b/src/PowerShellGet/private/functions/Publish-NugetPackage.ps1
@@ -18,6 +18,7 @@ function Publish-NugetPackage {
)
Set-StrictMode -Off
+ Write-Verbose "Calling Publish-NugetPackage -NupkgPath $NupkgPath -Destination $Destination -NugetExePath $NugetExePath -UseDotnetCli:$UseDotnetCli"
$Destination = $Destination.TrimEnd("\")
if ($PSCmdlet.ParameterSetName -eq "UseNuget") {
diff --git a/src/PowerShellGet/private/functions/Publish-PSArtifactUtility.ps1 b/src/PowerShellGet/private/functions/Publish-PSArtifactUtility.ps1
index 504ae5c0..33c27453 100644
--- a/src/PowerShellGet/private/functions/Publish-PSArtifactUtility.ps1
+++ b/src/PowerShellGet/private/functions/Publish-PSArtifactUtility.ps1
@@ -70,6 +70,7 @@ function Publish-PSArtifactUtility {
$Exclude
)
+ Write-Verbose "Calling Publish-PSArtifactUtility"
Install-NuGetClientBinaries -CallerPSCmdlet $PSCmdlet -BootstrapNuGetExe
$PSArtifactType = $script:PSArtifactTypeModule