Enable re-discovery of resources during deployment#1366
Merged
SteveL-MSFT merged 11 commits intoPowerShell:mainfrom Jan 28, 2026
Merged
Enable re-discovery of resources during deployment#1366SteveL-MSFT merged 11 commits intoPowerShell:mainfrom
SteveL-MSFT merged 11 commits intoPowerShell:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a new resourceDiscovery metadata option under the Microsoft.DSC namespace to support discovering resources during deployment, enabling scenarios where configurations install resources that are then used later in the same run.
Changes:
- Introduces a new
ResourceDiscoveryMode(preDeployment/duringDeployment) metadata option and wires it into configuration validation and the discovery pipeline, including dynamic re-discovery viaDiscovery.refresh_cacheandCommandDiscovery’s discovery mode. - Adds a new test-only resource
Test/CopyResource(implemented via thedsctesttool) that can copy an existing resource manifest and retarget itstype, plus a manifest entry and schema support for this resource. - Extends PowerShell tests to cover the new
resourceDiscoverybehavior, verifying both failure in pre-deployment mode and success when discovery happens during deployment.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
tools/dsctest/src/main.rs |
Wires a new copy-resource subcommand into dsctest, handling JSON input, invoking the copy helper, and exposing a schema for the new CopyResource input. |
tools/dsctest/src/copy_resource.rs |
Defines the CopyResource schema and implements copy_the_resource, which rewrites the type in a source manifest and emits a new .dsc.resource.json file for the desired type. |
tools/dsctest/src/args.rs |
Adds CopyResource to the Schemas enum and defines the copy-resource CLI subcommand used by the test resource manifest. |
tools/dsctest/dsctest.dsc.manifests.json |
Registers Test/CopyResource as a test resource backed by the dsctest binary, including schema wiring via the schema subcommand. |
lib/dsc-lib/src/discovery/mod.rs |
Extends the Discovery struct with a refresh_cache flag and updates find_resource/find_resources to support forced rediscovery using the new discovery mode. |
lib/dsc-lib/src/discovery/discovery_trait.rs |
Updates the ResourceDiscovery trait to be aware of ResourceDiscoveryMode and adds a set_discovery_mode method implemented by discovery backends. |
lib/dsc-lib/src/discovery/command_discovery.rs |
Tracks a discovery_mode in CommandDiscovery and adjusts its caching and discovery behavior so that DuringDeployment forces re-discovery while allowing pre-deployment caching when appropriate. |
lib/dsc-lib/src/configure/mod.rs |
Reads the new metadata.Microsoft.DSC.resourceDiscovery value, skips pre-deployment resource validation when set to duringDeployment, and sets Discovery.refresh_cache for runtime rediscovery. |
lib/dsc-lib/src/configure/config_doc.rs |
Defines the ResourceDiscoveryMode enum, adds it to MicrosoftDscMetadata, and updates serde metadata so resourceDiscovery is available in the config schema under the Microsoft.DSC namespace. |
lib/dsc-lib/locales/en-us.toml |
Adds a localized message indicating that resource discovery is being skipped due to resourceDiscovery: duringDeployment. |
dsc/tests/dsc_discovery.tests.ps1 |
Adds Pester tests covering resourceDiscovery modes, including a scenario that uses Test/CopyResource to install a resource during deployment and then invoke it in the same configuration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
tgauth
reviewed
Jan 27, 2026
tgauth
reviewed
Jan 27, 2026
tgauth
approved these changes
Jan 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
To support the scenario where the config installs resources that will get used later, this change introduces new metadata under the
Microsoft.DSCnamespace to enable re-discovery of resources during deployment:The new
resourceDiscoveryproperty acceptspreDeployment(the default) orduringDeployment.preDeploymentmeans that all resources (except within a group) are discovered and validated before deployment. So if any resource is missing, no resources are executed (this PR fixes that regression).For testing, this PR creates a new test resource where you can specify a manifest file to copy and rename the type name to simulate the installation of a new resource (the new resource still needs to adhere to current discovery rules).
One side effect here is that to support dynamically installed resources, before EVERY resource invocation, a discovery is performed. We can optimize this in the future later based on other ideas in the issue below.
This change required storing the mode in Discovery and also CommandDiscovery to force rediscovery since both previously optimized where if it had results cached, it skipped discovery every time.
Also fixed an issue in the
Install-Protobufhelper function aswingetreturns a non-zero exit code if the package is already installed. Fix is to use--forceto force an install.PR Context
Fix #1170