Skip to content

Commit cff7960

Browse files
authored
Fix bug with version parsing in Publish-PSResource (#1223)
1 parent 83c9e0c commit cff7960

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/code/PublishPSResource.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,10 @@ private string CreateNuspec(
543543
{
544544
if (psData.ContainsKey("prerelease") && psData["prerelease"] is string preReleaseVersion)
545545
{
546-
version = string.Format(@"{0}-{1}", version, preReleaseVersion);
546+
if (!string.IsNullOrEmpty(preReleaseVersion))
547+
{
548+
version = string.Format(@"{0}-{1}", version, preReleaseVersion);
549+
}
547550
}
548551

549552
if (psData.ContainsKey("licenseuri") && psData["licenseuri"] is string licenseUri)

test/PublishPSResourceTests/PublishPSResource.Tests.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,18 @@ Describe "Test Publish-PSResource" -tags 'CI' {
392392
(Get-ChildItem $script:destinationPath).FullName | Should -Be $expectedPath
393393
}
394394

395+
It "Publish a module with -Path -Repository and -DestinationPath" {
396+
$moduleName = "Pester"
397+
$moduleVersion = "5.5.0"
398+
Save-PSResource -Name $moduleName -Path $tmpRepoPath -Version $moduleVersion -Repository PSGallery -TrustRepository
399+
$modulePath = Join-Path -Path $tmpRepoPath -ChildPath $moduleName
400+
$moduleVersionPath = Join-Path -Path $modulePath -ChildPath $moduleVersion
401+
$moduleManifestPath = Join-path -Path $moduleVersionPath -ChildPath "$moduleName.psd1"
402+
Publish-PSResource -Path $moduleManifestPath -Repository $testRepository2
403+
$expectedPath = Join-Path -Path $script:repositoryPath2 -ChildPath "$moduleName.$moduleVersion.nupkg"
404+
(Get-ChildItem $script:repositoryPath2).FullName | Should -Be $expectedPath
405+
}
406+
395407
It "Publish a module and clean up properly when file in module is readonly" {
396408
$version = "1.0.0"
397409
New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module"

0 commit comments

Comments
 (0)