Skip to content

DefaultCommandPrefix from Module PSD ignored after recent patch #25419

Closed

Description

Prerequisites

Steps to reproduce

  • Import a PowerShell module with a DefaultCommandPrefix set in the .psd file
  • As an example, use my module totkeks.GitManagement from PowerShell gallery
  • Run command Set-GitBaseDirectory

Source of the error from this PR #20409 (comment), where it is not checking for String.IsNullOrEmpty() anymore, instead using just null coalescing ??, which doesn't include String.Empty.

Expected behavior

* Commands are prefixed with the defined prefix, e.g. `Git`, and are working / found in the current scope

Actual behavior

* Command not found, because the prefix was overwritten with an empty string

Error details

Environment data

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.6.0-preview.4
PSEdition                      Core
GitCommitId                    7.6.0-preview.4
OS                             Microsoft Windows 10.0.26200
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Activity

  1. iSazonov commented on Apr 22, 2025

    @iSazonov
    Collaborator

    Possible regression from #20409. It seems we skipped that BasePrefix is initialized with string.Empty.
    https://github.com/MartinGC94/PowerShell/blob/e18db00c8004f8b8639c9b65d922bb96e42e2ba9/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs#L120

    GitHub
    PowerShell for every system! Contribute to MartinGC94/PowerShell development by creating an account on GitHub.
  2. iSazonov commented on Apr 22, 2025

    @iSazonov
    Collaborator
  3. MartinGC94 commented on Apr 23, 2025

    @MartinGC94
    Contributor

    I think we are in luck. As far as I can tell, all other references to the prefix with a default value uses IsNullOrEmpty so a simple fix would be to just change the default value to a null.

  4. iSazonov commented on Apr 24, 2025

    @iSazonov
    Collaborator

    I'm just afraid that there are too few tests to avoid regression. They should be added.

  5. MartinGC94 commented on Apr 24, 2025

    @MartinGC94
    Contributor

    It's a very complicated code area for sure. TBH I don't see myself investing the time and effort to dig further into this so unless someone else steps up we can also just revert the change.

  6. iSazonov commented on Apr 25, 2025

    @iSazonov
    Collaborator

    we can also just revert the change

    MartinGC94 Please pull the revert PR.

  7. microsoft-github-policy-service commented on Apr 28, 2025

    @microsoft-github-policy-service
    Contributor

    📣 Hey @Norman Dankert (@totkeks), how did we do? We would love to hear your feedback with the link below! 🗣️

    🔗 https://aka.ms/PSRepoFeedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    WG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions