diff --git a/src/code/CompressPSResource.cs b/src/code/CompressPSResource.cs index 95b95a4e3..b306e7d88 100644 --- a/src/code/CompressPSResource.cs +++ b/src/code/CompressPSResource.cs @@ -3,7 +3,6 @@ using Microsoft.PowerShell.PSResourceGet.UtilClasses; using System.IO; -using System.Linq; using System.Management.Automation; namespace Microsoft.PowerShell.PSResourceGet.Cmdlets @@ -15,6 +14,7 @@ namespace Microsoft.PowerShell.PSResourceGet.Cmdlets "PSResource", SupportsShouldProcess = true)] [Alias("cmres")] + [OutputType(typeof(FileInfo))] public sealed class CompressPSResource : PSCmdlet { #region Parameters diff --git a/src/code/PublishHelper.cs b/src/code/PublishHelper.cs index 861bbfab3..f7ef9248b 100644 --- a/src/code/PublishHelper.cs +++ b/src/code/PublishHelper.cs @@ -566,7 +566,8 @@ private bool PackNupkg(string outputDir, string outputNupkgDir, string nuspecFil { if (PassThru) { - _cmdletPassedIn.WriteObject(System.IO.Path.Combine(outputNupkgDir, _pkgName + "." + _pkgVersion.ToNormalizedString() + ".nupkg")); + var nupkgPath = System.IO.Path.Combine(outputNupkgDir, _pkgName + "." + _pkgVersion.ToNormalizedString() + ".nupkg"); + _cmdletPassedIn.WriteObject(new FileInfo(nupkgPath)); } _cmdletPassedIn.WriteVerbose("Successfully packed the resource into a .nupkg"); } diff --git a/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 b/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 index 778c225bb..7a54d72d6 100644 --- a/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 +++ b/test/PublishPSResourceTests/CompressPSResource.Tests.ps1 @@ -154,14 +154,17 @@ Describe "Test Compress-PSResource" -tags 'CI' { Test-Path -Path (Join-Path -Path $unzippedPath -ChildPath $testFile) | Should -Be $True } - It "Compress-PSResource -PassThru returns the path to the nupkg" { + It "Compress-PSResource -PassThru returns a FileInfo object with the correct path" { $version = "1.0.0" New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module" - $nupkgPath = Compress-PSResource -Path $script:PublishModuleBase -DestinationPath $script:repositoryPath -PassThru + $fileInfoObject = Compress-PSResource -Path $script:PublishModuleBase -DestinationPath $script:repositoryPath -PassThru $expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$script:PublishModuleName.$version.nupkg" - $nupkgPath | Should -Be $expectedPath + $fileInfoObject | Should -BeOfType 'System.IO.FileSystemInfo' + $fileInfoObject.FullName | Should -Be $expectedPath + $fileInfoObject.Extension | Should -Be '.nupkg' + $fileInfoObject.Name | Should -Be "$script:PublishModuleName.$version.nupkg" } <# Test for Signing the nupkg. Signing doesn't work