Skip to content

Add PowerShell script execution feature flag infrastructure - #7858

Merged
zivkan merged 5 commits into
devfrom
dev-zivkan-feature-flag-infrastructure
Nov 20, 2026
Merged

zivkan merged 5 commits into
devfrom
dev-zivkan-feature-flag-infrastructure

Conversation

@zivkan

@zivkan zivkan commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Bug

Towards: NuGet/Home#15141

Description

Extracts the feature-flag infrastructure from #7771 as a smaller PR to review. This PR doesn't change any functionality, just puts the feature flag in place, for later PRs to use.

Registers the native Visual Studio flag NuGet.ControlPowerShellScriptExecution, defaulting to off, and publishes its resolved value through AppContext during NuGet package initialization. This allows NuGet "core" libraries that can't use the VSSDK, to be able to read the flag value and change behavior.

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. N/A

@zivkan
zivkan added this pull request to stack #7859 November 6, 2026 02:40
@zivkan
zivkan marked this pull request as ready for review November 6, 2026 03:17
@zivkan
zivkan requested a review from a team as a code owner November 6, 2026 03:17
@zivkan
zivkan requested a review from jebriede November 10, 2026 20:15
jebriede
jebriede previously approved these changes Nov 10, 2026
Base automatically changed from dev-zivkan-package-identity-shared-code to dev November 16, 2026 20:08
@zivkan
zivkan force-pushed the dev-zivkan-feature-flag-infrastructure branch from 48c777e to 61d2dce Compare November 17, 2026 00:27
@zivkan
zivkan requested a review from jebriede November 17, 2026 18:59
@Nigusu-Allehu
Nigusu-Allehu self-requested a review November 17, 2026 23:51

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

Loading NuGetPackage alone no longer initializes the feature flags, and changing the serializer switch mid-connection can cause queued plugin payload decoding to throw InvalidCastException.

2 open issues
What changed in this PR

Adds default-off PowerShell script-execution feature-flag infrastructure for future NuGet behavior changes. It bridges Visual Studio flag resolution to core libraries through AppContext, without yet changing automatic script execution.

Changes:

  • Defines the PowerShell flag and environment override, with shared asynchronous initialization.
  • Adds initialization guards to solution-manager and PowerShell-host entry points and makes JSON-switch reads dynamic.
  • Adds tests for switch changes, override precedence, shared initialization, and failure handling.
File Description
test/​NuGet.Core.Tests/​NuGet.Protocol.Tests/​NuGetFeatureFlagsTests.cs Tests dynamic JSON-switch reads.
test/​NuGet.Core.Tests/​NuGet.PackageManagement.Test/​NuGetFeatureFlagsTests.cs Tests PowerShell flag overrides and switch changes.
test/​NuGet.Clients.Tests/​NuGetConsole.Host.PowerShell.Test/​PowerShellHostTests.cs Tests initialization waiting and failure handling.
test/​NuGet.Clients.Tests/​NuGet.VisualStudio.Common.Test/​NuGetFeatureFlagInitializerTests.cs Tests switch publication and shared initialization.
test/​NuGet.Clients.Tests/​NuGet.PackageManagement.VisualStudio.Test/​VSSolutionManagerTest.cs Tests initialization gating and failure propagation.
src/​NuGet.Core/​NuGet.PackageManagement/​NuGet.PackageManagement.csproj Includes shared flag and compatibility helpers.
src/​NuGet.Clients/​NuGet.VisualStudio.Common/​Services/​NuGetFeatureFlagInitializer.cs Adds shared asynchronous switch publication.
src/​NuGet.Clients/​NuGet.VisualStudio.Common/​Services/​NuGetFeatureFlagConstants.cs Defines the default-off PowerShell flag.
src/​NuGet.Clients/​NuGet.VisualStudio.Common/​Services/​INuGetFeatureFlagInitializer.cs Defines the initialization contract.
src/​NuGet.Clients/​NuGet.Tools/​NuGetPackage.cs Removes direct JSON-switch publication.
src/​NuGet.Clients/​NuGet.PackageManagement.VisualStudio/​IDE/​VSSolutionManager.cs Awaits flags before project initialization.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​PowerShellHost.cs Awaits flags before host initialization.
src/​NuGet.Clients/​NuGet.PackageManagement.PowerShellCmdlets/​NuGet.PackageManagement.PowerShellCmdlets.csproj Includes shared flag and compatibility helpers.
build/​Shared/​NuGetFeatureFlags.cs Adds PowerShell flag reads and dynamic JSON-switch access.

Review effort: Balanced

Comment thread build/Shared/NuGetFeatureFlags.cs Resolved

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.

🟢 Approval recommended

No active review issues remain for the default-off PowerShell feature-flag infrastructure.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

zivkan and others added 5 commits November 20, 2026 13:59
Extract the default-off VS feature flag and shared AppContext bridge for the next init-script layer, without changing script execution behavior.

Co-authored-by: Copilot App <[email protected]>
Inject the environment reader, remove redundant cases, and isolate switch refresh coverage. Use the shared environment variable constant consistently and keep the feature guide general.

Co-authored-by: Copilot App <[email protected]>
Gate solution manager and PowerShell host initialization on a shared,
one-time initializer for feature flags and experiments, independent of
NuGetPackage load order.

Move System.Text.Json experiment publication into shared initialization
and read its AppContext switch dynamically to avoid caching an early value.

Add focused regression coverage and document shared initialization.

Co-authored-by: Copilot App <[email protected]>
Move AppContext switch publication into a dedicated initializer that
coordinates feature flags and experiments. Keep the query services
independent and update solution manager and PowerShell host gates.

Consolidate shared flag readers into NuGetFeatureFlags, preserving
environment override behavior and isolating the JSON cache.

Move initialization guidance from the feature guide to service comments
and relocate the focused regression tests.

Co-authored-by: Copilot App <[email protected]>
Keep JSON serializer selection cached and initialize shared flags during NuGetPackage initialization, retaining the solution-manager and PMC gates.

Log lookup failures without blocking NuGet operations or retrying until VS restarts. Move solution-manager initialization inside its try/catch and after the initialized check.

Co-authored-by: Copilot App <[email protected]>
@zivkan
zivkan force-pushed the dev-zivkan-feature-flag-infrastructure branch from f35ce44 to 2ba051a Compare November 20, 2026 03:29
@zivkan
zivkan enabled stacked auto-merge (squash) November 20, 2026 03:30
@zivkan
zivkan merged commit e6a245b into dev Nov 20, 2026
17 of 18 checks passed
@zivkan
zivkan deleted the dev-zivkan-feature-flag-infrastructure branch November 20, 2026 04:24
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