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

Resolve 'Publish-Module doesn't report error but fails to publish module' #332

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
6 changes: 5 additions & 1 deletion PowerShellGet/PowerShellGet.psd1
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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
Expand Down
24 changes: 22 additions & 2 deletions PowerShellGet/private/functions/Publish-PSArtifactUtility.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.') )
Expand Down