Skip to content

Add support for _refreshEnv resource metadata to update env vars on Windows during deployment#1408

Open
SteveL-MSFT wants to merge 8 commits intoPowerShell:mainfrom
SteveL-MSFT:refreshEnv
Open

Add support for _refreshEnv resource metadata to update env vars on Windows during deployment#1408
SteveL-MSFT wants to merge 8 commits intoPowerShell:mainfrom
SteveL-MSFT:refreshEnv

Conversation

@SteveL-MSFT
Copy link
Member

@SteveL-MSFT SteveL-MSFT commented Feb 26, 2026

PR Summary

On a set operation, if the resource returns _refreshEnv = true, then on Windows the system env vars are read from the registry and the user env vars are layered on top. In the case of PATH specifically, the user PATH value is prefixed to the system one. The dsc process env vars get updated and child processes continue to inherit.
On non-Windows systems, if a resource returns _refreshEnv metadata, an INFO message is logged indicating it is ignored.

A new dsctest resource was created to update the user registry with the indicated env var.

This change does add a dependency on the registry crate to dsc-lib.

PR Context

Fix #430

@SteveL-MSFT SteveL-MSFT changed the title Refresh env Add support for _refreshEnv resource metadata to update env vars on Windows during deployment Feb 26, 2026
@SteveL-MSFT SteveL-MSFT marked this pull request as draft February 27, 2026 01:09
@SteveL-MSFT
Copy link
Member Author

Need to redo this PR, originally separated the env vars in a cache to not pollute the process ones, but dsc needs to use the new PATH if winget installs an app that includes resources, so need to update the process env vars instead of a cache

@SteveL-MSFT SteveL-MSFT marked this pull request as ready for review February 27, 2026 23:09
@SteveL-MSFT SteveL-MSFT added Doc-Impact Schema-Impact Change requires updating a canonical schema for configs or manifests labels Feb 27, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for a _refreshEnv metadata flag so DSC can refresh its process environment from the Windows registry after a resource set, enabling subsequent resources to observe newly-installed tooling (e.g., updated PATH). Also introduces a new Test/RefreshEnv dsctest resource plus test coverage to validate the behavior.

Changes:

  • Implement _refreshEnv metadata handling in dsc-lib (Windows refresh; non-Windows logs INFO and ignores).
  • Add Test/RefreshEnv dsctest resource/CLI plumbing and manifest/schema entries.
  • Add Pester tests covering env refresh behavior (including PATH) and wire in new registry dependency (Windows).

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tools/dsctest/src/refresh_env.rs New dsctest resource that writes/reads user env vars via HKCU registry.
tools/dsctest/src/main.rs Adds refresh-env subcommand handling and schema generation for RefreshEnv.
tools/dsctest/src/args.rs Adds RefreshEnvOperation and the refresh-env clap subcommand + schema enum entry.
tools/dsctest/dsctest.dsc.manifests.json Registers new Test/RefreshEnv resource manifest for get/set + schema command.
tools/dsctest/Cargo.toml Adds registry and utfx deps for the new dsctest module.
lib/dsc-lib/src/dscerror.rs Adds Windows registry-related error variants + UTF-16 conversion error.
lib/dsc-lib/src/discovery/command_discovery.rs Refactors resource construction to use DscResource::new() then field assignment.
lib/dsc-lib/src/configure/mod.rs Implements _refreshEnv metadata handling and Windows registry env read/merge helper.
lib/dsc-lib/src/configure/context.rs Derives Debug for Context.
lib/dsc-lib/locales/en-us.toml Adds localized strings for _refreshEnv messages and registry/UTF-16 errors.
lib/dsc-lib/Cargo.toml Adds Windows-only dependency on registry.
helpers.build.psm1 Adds sudo apt update before installing protobuf via apt.
dsc/tests/dsc_metadata.tests.ps1 Adds integration tests for _refreshEnv behavior (including PATH).
Cargo.toml Updates workspace comments to include new registry/utfx usage.
Cargo.lock Locks new/updated transitive deps due to added crates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

Doc-Impact Schema-Impact Change requires updating a canonical schema for configs or manifests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ability to update PATH env var for current DSC process

2 participants