Skip to content

Add Get-PackageInitScript to discover installed init scripts - #7771

Open
zivkan wants to merge 8 commits into
devfrom
dev-zivkan-init-script-execution
Open

zivkan wants to merge 8 commits into
devfrom
dev-zivkan-init-script-execution

Conversation

@zivkan

@zivkan zivkan commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Bug

Towards: NuGet/Home#15141
Spec: https://github.com/NuGet/Home/blob/dev/accepted/2026/control-powershell-script-execution.md

Description

Adds only Get-PackageInitScript, the discovery portion of the PowerShell script execution spec, as layer 3 above shared name@version parsing (#7857) and feature flag infrastructure (#7858).

The cmdlet lists installed solution packages' tools/init.ps1 scripts without executing them, returning package ID, version, and absolute path as FullName. It preserves solution-level dependency ordering and deduplication, supports optional package selectors (including id@version), and includes tab completion and help. The command is guarded by the default-off NuGet.ControlPowerShellScriptExecution feature flag.

Automatic init.ps1, install.ps1, and uninstall.ps1 execution is unchanged, even when the flag is enabled. Import-PackageInitScript and the changes disabling automatic initialization are deferred to a subsequent stacked PR, together with their execution and Apex lifecycle coverage.

Includes discovery-only cmdlet coverage for feature gating, package selection and errors, ordering and deduplication, packages.config, and PackageReference global/fallback folders. The about-help file and localization pipeline configuration remain unchanged.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Since this PR is changing CI as it modifies YML files, please verify that you've addressed how this change should apply to release branches. Either:

  • Link to equivalent PRs or Issues for each currently supported branch.
    or
  • Explain in the PR description why this change doesn't apply to release branches.

@zivkan
zivkan marked this pull request as ready for review October 14, 2026 11:09
@zivkan
zivkan requested a review from a team as a code owner October 14, 2026 11:09
@zivkan
zivkan requested review from jeffkl and nkolev92 October 14, 2026 11:09
@zivkan
zivkan force-pushed the dev-zivkan-init-script-execution branch from cd68f6b to c503422 Compare October 15, 2026 19:05
@zivkan
zivkan force-pushed the dev-zivkan-init-script-execution branch from 5d6d1fc to d2d8a53 Compare October 20, 2026 10:13
@Nigusu-Allehu
Nigusu-Allehu self-requested a review October 20, 2026 22:58

@nkolev92 nkolev92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's hide this behind a feature flag as we discussed.

@zivkan
zivkan marked this pull request as draft October 21, 2026 00:51
@zivkan
zivkan changed the base branch from dev to dev-zivkan-feature-flag-infrastructure November 6, 2026 02:50
@zivkan
zivkan added this pull request to stack #7859 November 6, 2026 02:51
@zivkan zivkan changed the title init.ps1 no longer runs automatically in VS Add Get-PackageInitScript to discover installed init scripts Nov 10, 2026
zivkan added a commit that referenced this pull request Nov 16, 2026
* Share name@version parsing through PackageIdentity

Extract the shared parser and XPlat adoption from #7771 as the bottom layer of the init-script PR stack.

Co-authored-by: Copilot App <[email protected]>

* Address PackageIdentity parsing API review feedback

Rename ParseAtSeparated to Parse and add TryParse. Update callers, API baselines, and tests, including assertions that preserve the original version string and build metadata.

Co-authored-by: Copilot App <[email protected]>

* Refine PackageIdentity parsing validation and shared logic

Remove package ID length enforcement from Parse and TryParse. Share separator handling through GetParts, declare the parsed version inline, and verify long IDs parse successfully.

Co-authored-by: Copilot App <[email protected]>

---------

Co-authored-by: Copilot App <[email protected]>
@zivkan
zivkan force-pushed the dev-zivkan-init-script-execution branch from fb3f4aa to 2365d28 Compare November 17, 2026 03:37
@zivkan
zivkan marked this pull request as ready for review November 17, 2026 04:43
@zivkan

zivkan commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

This PR is now very different to when I originally opened it. It now is just the changes for the Get-PackageInitScript PMC command. See the other stacked PRs for the rest of the feature.

@zivkan
zivkan requested review from jeffkl and nkolev92 November 17, 2026 04:44
jeffkl
jeffkl previously approved these changes Nov 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Tab completion fails after the first comma-separated package selector because it matches the entire argument instead of the current element; the completion logic and a multi-package regression test are needed.

1 open issue
1 file not reviewed
  • src/NuGet.Clients/NuGet.PackageManagement.PowerShellCmdlets/Resources.Designer.cs: Generated file
What changed in this PR

Adds feature-gated Get-PackageInitScript discovery to NuGet’s Package Manager Console, building on shared package-selector parsing and feature-flag infrastructure. Automatic script execution remains unchanged.

Changes:

  • Discovers installed tools/init.ps1 scripts in dependency order, with deduplication and optional id@version selection.
  • Adds command export, tab completion, help, and localizable error messages.
  • Adds tests for feature gating, selection, ordering, and packages.config and PackageReference discovery.
File Description
test/​NuGet.Clients.Tests/​NuGetConsole.Host.PowerShell.Test/​Fixtures/​CmdletRunspaceFixture.cs Registers the cmdlet and captures script invocation errors.
test/​NuGet.Clients.Tests/​NuGetConsole.Host.PowerShell.Test/​Cmdlets/​PackageInitScriptCommandTests.cs Tests discovery behavior without script execution.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​xlf/​Resources.zh-Hant.xlf Adds Traditional Chinese localization entries.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​xlf/​Resources.zh-Hans.xlf Adds Simplified Chinese localization entries.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​xlf/​Resources.tr.xlf Adds Turkish localization entries.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​xlf/​Resources.ru.xlf Adds Russian localization entries.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​xlf/​Resources.pt-BR.xlf Adds Brazilian Portuguese localization entries.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​xlf/​Resources.pl.xlf Adds Polish localization entries.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​xlf/​Resources.ko.xlf Adds Korean localization entries.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​xlf/​Resources.ja.xlf Adds Japanese localization entries.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​xlf/​Resources.it.xlf Adds Italian localization entries.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​xlf/​Resources.fr.xlf Adds French localization entries.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​xlf/​Resources.es.xlf Adds Spanish localization entries.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​xlf/​Resources.de.xlf Adds German localization entries.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​xlf/​Resources.cs.xlf Adds Czech localization entries.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​Utils/​PackageInitScriptHelper.cs Implements feature gating, discovery, and selector matching.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​Utility/​NuGetErrorId.cs Defines the unmatched-selector error identifier.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​Scripts/​nuget.psm1 Registers package-selector tab completion.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​Scripts/​NuGet.psd1 Exports the new cmdlet.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​Scripts/​NuGet.PackageManagement.PowerShellCmdlets.dll-Help.xml Documents discovery, selectors, output, and examples.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​Resources.resx Adds feature-disabled and unmatched-selector messages.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​Resources.Designer.cs Adds generated resource accessors.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​Model/​PowerShellPackageInitScript.cs Defines output containing package identity and script path.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​Cmdlets/​GetPackageInitScriptCommand.cs Implements the discovery cmdlet and optional selectors.

Review effort: Balanced

@zivkan
zivkan force-pushed the dev-zivkan-init-script-execution branch from d8754ba to 99e74a8 Compare November 20, 2026 03:39
Base automatically changed from dev-zivkan-feature-flag-infrastructure to dev November 20, 2026 04:24
zivkan and others added 8 commits November 20, 2026 14:54
Preserve legacy initialization while the feature is disabled and exercise both flag states in Apex. Restore the original about-help and localization configuration.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b0280b67-b29c-46a2-b801-e89275774e12
Defer explicit import, automatic init-script execution controls, and their lifecycle coverage to the next stack layer.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b0280b67-b29c-46a2-b801-e89275774e12
List all matching installed package versions without ambiguity errors.
Simplify feature-disabled wording and remove activation instructions.
Clarify discovery help and regenerate resources with Dev18.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: b0280b67-b29c-46a2-b801-e89275774e12
Preserve preceding selectors when completing comma-separated package arguments. Handle empty completion matches and cover the shipped module with runspace tests.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: b0280b67-b29c-46a2-b801-e89275774e12
@zivkan
zivkan force-pushed the dev-zivkan-init-script-execution branch from 99e74a8 to 122e511 Compare November 20, 2026 04:24
@zivkan
zivkan requested a balanced review from Copilot November 20, 2026 05:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Package completion fails for valid comma-and-whitespace-separated arrays because later elements are parsed as positional arguments, requiring parsing and replacement fixes plus a regression test.

1 open issue
1 resolved since last review
1 file not reviewed
  • src/NuGet.Clients/NuGet.PackageManagement.PowerShellCmdlets/Resources.Designer.cs: Generated file

Review effort: Balanced

Comment on lines +48 to +49
Register-TabExpansion 'Get-PackageInitScript' @{
'Packages' = {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants