Skip to content

Publish-PSResource is generating incorrect dependency version range for RequiredModules in nuspec #1777

Closed
@afroz429

Description

@afroz429

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.

The publishing process for AWS Tools for PowerShell modules was switched from Publish-Module to Publish-PSResource to publish modules to the PowerShellGallery. Publish-PSResource is creating incorrect dependencies for the same module manifest file.

AWS.Tools.CloudWatch module version 4.1.730 was published using Publish-Module. Under the Package Details section, the dependency shows as expected AWS.Tools.Common (= 4.1.730)

For the same module published with Publish-PSResource the dependency shows as AWS.Tools.Common (>= 4.1.741)

As can be seen from the module manifest file, the RequiredModules section is shown below. Since the RequiredVersion was specified, the module dependency should be equal to the version not greater than equal to the version.

 RequiredModules = @(
        @{
            ModuleName = 'AWS.Tools.Common';
            RequiredVersion = '4.1.741';
            Guid = 'e5b05bf3-9eee-47b2-81f2-41ddc0501b86' }
    )

It appears that the nuget package that is generated has the following in the nuspec file.

Publish-Module has <dependency id="ModuleCore" version="[0.0.1]" />

Publish-PSResource has <dependency id="ModuleCore" version="0.0.1" />

Which according to nuget package version documentation is exact version or greater than equal to.

Notation Applied rule Description
1.0 x ≥ 1.0 Minimum version, inclusive
[1.0] x == 1.0 Exact version match

Steps to reproduce

  • Create ModuleCore with version 0.0.1 with guid 80368ccb-08f5-4e6c-b341-b17f40985e73
  • Create MyModule with version 0.0.1 with guid 508e05e9-17e1-4951-a60b-4d120775bdbc
  • In MyModule manifest file, set the RequiredModules section as shown below
    RequiredModules   = @(
        @{
            ModuleName      = 'ModuleCore';
            RequiredVersion = '0.0.1';
            Guid            = '80368ccb-08f5-4e6c-b341-b17f40985e73' 
        }
    )
  • Publish module to local ps repository using Publish-PSResource.
Publish-PSResource -Path ModuleCore\ModuleCore.psd1 -Repository LocalFileRepo
Publish-PSResource -Path ModuleCore\MyModule.psd1 -Repository LocalFileRepo
  • Inspect the generated nuspec file from MyModule

Expected behavior

Since the `RequiredVersion` is specified in the `RequiredModules` section, the dependency should be an exact match.

Actual behavior

The dependency is created as greater than equal to the version specified in the `RequiredVersion`

Error details

It appears that the code is treating ModuleVersion and RequiredVersion as same.

See
https://github.com/PowerShell/PSResourceGet/blob/v1.1.0/src/code/PublishHelper.cs#L1177-L1184
https://github.com/PowerShell/PSResourceGet/blob/v1.1.0/src/code/PublishHelper.cs#L1134

Environment data

Production is using `1.0.6 ` . We tried the latest `1.1.0`. Both have the same issue.


➜ Get-Module Microsoft.PowerShell.PSResourceGet ;$PSVersiontable | format-table

    Directory: C:\Users\user\Documents\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Binary     1.1.0                 Microsoft.PowerShell.PSResourceGet  Core,Desk {Compress-PSResource, Find-PSResource, …


Name                           Value
----                           -----
PSVersion                      7.4.6
PSEdition                      Core
GitCommitId                    7.4.6
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

Nuspec Publish-Module vs Publish-PSResource screenshot

Image

PowerShell Gallery dependency using Publish-Module :

Image

PowerShellGallery dependency using Publish-PSResource
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions