Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

Commit b47b406

Browse files
authored
Resolve 'Publish-Module doesn't report error but fails to publish module' (#316) (#332)
This is happening due to the latest version of dotnet cli is not writing the error messages into error stream
1 parent f0728e0 commit b47b406

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Changelog
2+
## 2.0.1
3+
Bug fix
4+
- Resolved Publish-Module doesn't report error but fails to publish module (#316)
5+
26
## 2.0.0
37
Breaking Change
48
- 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.

PowerShellGet/PowerShellGet.psd1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@{
22
RootModule = 'PSModule.psm1'
3-
ModuleVersion = '2.0.0'
3+
ModuleVersion = '2.0.1'
44
GUID = '1d73a601-4a6c-43c5-ba3f-619b18bbb404'
55
Author = 'Microsoft Corporation'
66
CompanyName = 'Microsoft Corporation'
@@ -54,6 +54,10 @@ PrivateData = @{
5454
ProjectUri = 'https://go.microsoft.com/fwlink/?LinkId=828955'
5555
LicenseUri = 'https://go.microsoft.com/fwlink/?LinkId=829061'
5656
ReleaseNotes = @'
57+
## 2.0.1
58+
Bug fix
59+
- Resolved Publish-Module doesn't report error but fails to publish module (#316)
60+
5761
## 2.0.0
5862
5963
Breaking Change

PowerShellGet/private/functions/Publish-PSArtifactUtility.ps1

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -515,11 +515,13 @@ $CsprojContent = @"
515515
$tempOutputFile = Microsoft.PowerShell.Management\Join-Path -Path $nugetPackageRoot -ChildPath "TempPublishOutput.txt"
516516

517517
$errorMsg = $null
518+
$outputMsg = $null
518519
$StartProcess_params = @{
519520
RedirectStandardError = $tempErrorFile
520521
RedirectStandardOutput = $tempOutputFile
521522
NoNewWindow = $true
522523
Wait = $true
524+
PassThru = $true
523525
}
524526

525527
if($script:DotnetCommandPath) {
@@ -547,13 +549,31 @@ $CsprojContent = @"
547549
$StartProcess_params['Confirm'] = $false
548550
}
549551

550-
Microsoft.PowerShell.Management\Start-Process @StartProcess_params
552+
$process = Microsoft.PowerShell.Management\Start-Process @StartProcess_params
551553

552554
if(Test-Path -Path $tempErrorFile -PathType Leaf) {
553555
$errorMsg = Microsoft.PowerShell.Management\Get-Content -Path $tempErrorFile -Raw
556+
557+
if($errorMsg) {
558+
Write-Verbose -Message $errorMsg
559+
}
560+
}
561+
562+
if(Test-Path -Path $tempOutputFile -PathType Leaf) {
563+
$outputMsg = Microsoft.PowerShell.Management\Get-Content -Path $tempOutputFile -Raw
564+
565+
if($outputMsg) {
566+
Write-Verbose -Message $outputMsg
567+
}
568+
}
569+
570+
# The newer version of dotnet cli writes the error message into output stream instead of error stream
571+
# Get the error message from output stream when ExitCode is non zero (error).
572+
if($process -and $process.ExitCode -and -not $errorMsg -and $outputMsg) {
573+
$errorMsg = $outputMsg
554574
}
555575

556-
if($errorMsg)
576+
if(-not $process -or $process.ExitCode)
557577
{
558578
if(($NugetApiKey -eq 'VSTS') -and
559579
($errorMsg -match 'Cannot prompt for input in non-interactive mode.') )

0 commit comments

Comments
 (0)