From e701f25c430788aecf3fa0627befb1aadc826d97 Mon Sep 17 00:00:00 2001 From: Manikyam Bavandla Date: Fri, 21 Sep 2018 15:09:28 -0700 Subject: [PATCH] Resolve 'Publish-Module doesn't report error but fails to publish module' (#316) This is happening due to the latest version of dotnet cli is not writing the error messages into error stream --- CHANGELOG.md | 4 ++++ PowerShellGet/PowerShellGet.psd1 | 6 ++++- .../functions/Publish-PSArtifactUtility.ps1 | 24 +++++++++++++++++-- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f631cba5..fee2c2c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +## 2.0.1 +Bug fix +- Resolved Publish-Module doesn't report error but fails to publish module (#316) + ## 2.0.0 Breaking Change - Default installation scope for Install-Module, Install-Script, and Install-Package has changed. For Windows PowerShell (version 5.1 or below), the default scope is AllUsers when running in an elevated session, and CurrentUser at all other times. diff --git a/PowerShellGet/PowerShellGet.psd1 b/PowerShellGet/PowerShellGet.psd1 index a3b335e7..e8bad743 100644 --- a/PowerShellGet/PowerShellGet.psd1 +++ b/PowerShellGet/PowerShellGet.psd1 @@ -1,6 +1,6 @@ @{ RootModule = 'PSModule.psm1' -ModuleVersion = '2.0.0' +ModuleVersion = '2.0.1' GUID = '1d73a601-4a6c-43c5-ba3f-619b18bbb404' Author = 'Microsoft Corporation' CompanyName = 'Microsoft Corporation' @@ -54,6 +54,10 @@ PrivateData = @{ ProjectUri = 'https://go.microsoft.com/fwlink/?LinkId=828955' LicenseUri = 'https://go.microsoft.com/fwlink/?LinkId=829061' ReleaseNotes = @' +## 2.0.1 +Bug fix +- Resolved Publish-Module doesn't report error but fails to publish module (#316) + ## 2.0.0 Breaking Change diff --git a/PowerShellGet/private/functions/Publish-PSArtifactUtility.ps1 b/PowerShellGet/private/functions/Publish-PSArtifactUtility.ps1 index aca487d7..390b1051 100644 --- a/PowerShellGet/private/functions/Publish-PSArtifactUtility.ps1 +++ b/PowerShellGet/private/functions/Publish-PSArtifactUtility.ps1 @@ -515,11 +515,13 @@ $CsprojContent = @" $tempOutputFile = Microsoft.PowerShell.Management\Join-Path -Path $nugetPackageRoot -ChildPath "TempPublishOutput.txt" $errorMsg = $null + $outputMsg = $null $StartProcess_params = @{ RedirectStandardError = $tempErrorFile RedirectStandardOutput = $tempOutputFile NoNewWindow = $true Wait = $true + PassThru = $true } if($script:DotnetCommandPath) { @@ -547,13 +549,31 @@ $CsprojContent = @" $StartProcess_params['Confirm'] = $false } - Microsoft.PowerShell.Management\Start-Process @StartProcess_params + $process = Microsoft.PowerShell.Management\Start-Process @StartProcess_params if(Test-Path -Path $tempErrorFile -PathType Leaf) { $errorMsg = Microsoft.PowerShell.Management\Get-Content -Path $tempErrorFile -Raw + + if($errorMsg) { + Write-Verbose -Message $errorMsg + } + } + + if(Test-Path -Path $tempOutputFile -PathType Leaf) { + $outputMsg = Microsoft.PowerShell.Management\Get-Content -Path $tempOutputFile -Raw + + if($outputMsg) { + Write-Verbose -Message $outputMsg + } + } + + # The newer version of dotnet cli writes the error message into output stream instead of error stream + # Get the error message from output stream when ExitCode is non zero (error). + if($process -and $process.ExitCode -and -not $errorMsg -and $outputMsg) { + $errorMsg = $outputMsg } - if($errorMsg) + if(-not $process -or $process.ExitCode) { if(($NugetApiKey -eq 'VSTS') -and ($errorMsg -match 'Cannot prompt for input in non-interactive mode.') )