Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
afroz429 opened this issue Jan 23, 2025 · 0 comments

Comments

@afroz429
Copy link

afroz429 commented Jan 23, 2025

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

@afroz429 afroz429 changed the title Publish-PSResource is generating incorrect dependency version for RequiredModules in nuspec Publish-PSResource is generating incorrect dependency version range for RequiredModules in nuspec Jan 23, 2025
afroz429 pushed a commit to afroz429/PSResourceGet that referenced this issue Jan 24, 2025
…hen versions are specified in RequiredModules section

Fixes bug with generated nuspec dependency version range when RequiredVersion, MaxiumumVersion and ModuleVersion are specified in RequiredModules section
afroz429 pushed a commit to afroz429/PSResourceGet that referenced this issue Jan 24, 2025
…hen versions are specified in RequiredModules section

Fixes bug with generated nuspec dependency version range when RequiredVersion,MaxiumumVersion and ModuleVersion are specified in RequiredModules section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant