Skip to content

fix: align BuiltModuleSubdirectory property default in WorkspaceDependencies task - #594

Open
raandree wants to merge 4 commits into
gaelcolas:mainfrom
raandree:fix-#593
Open

fix: align BuiltModuleSubdirectory property default in WorkspaceDependencies task#594
raandree wants to merge 4 commits into
gaelcolas:mainfrom
raandree:fix-#593

Conversation

@raandree

@raandree raandree commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #593.

WorkspaceDependencies.build.ps1 was the only task file defaulting to
(property BuiltModuleSubdirectory 'module') — every other one uses ''.

InvokeBuild dot-sources all task files into the same scope, and property treats
an empty string as unset. Since this file is dot-sourced last, its non-empty
default overwrote $BuiltModuleSubdirectory for the whole build. Projects that
don't set it in build.yaml build to the output root, but the tasks then looked
under output\module and died in Build_DscResourcesToExport_ModuleBuilder with
"Could not find the built module manifest for module ''". Hit on
SharePointDsc; 0.119.1 was fine.

Changed the default to '' and updated the parameter help. The task still passes
the value to Get-SamplerWorkspaceLinkedModuleRoot, so the link root follows
wherever the project actually builds.

Fixed

Tests

  • Unit test asserting the property default is empty.
  • QA test checking all .build/tasks/*.build.ps1 agree — that's the one that
    catches this class of bug next time.

Both fail on the unfixed file. Also verified end-to-end against a scratch project
without BuiltModuleSubdirectory: fails before, builds after. Sampler itself sets
BuiltModuleSubdirectory: module so it never reproduced the bug and is unaffected.

Side note, not fixed here: generateHelp.PlatyPS.build.ps1 uses a relative
(property OutputDirectory 'output') while the rest use Join-Path $BuildRoot 'output'. Harmless today (it's always already set, and everything resolves it via
Get-SamplerAbsolutePath), but worth tidying separately.

Checklist

  • Single logical change; unrelated/cosmetic updates are in a separate PR.
  • CHANGELOG.md updated under Unreleased (format).
  • build.ps1 -ResolveDependency builds and tests pass locally.
  • Docs/comment-based help/localization updated where relevant.
  • Unit/integration tests added or updated (testing guidelines).
  • Code follows DSC Community Style Guidelines.

This change is Reviewable

$linkedModuleRootParams = @{
BuildRoot = $BuildRoot
OutputDirectory = $OutputDirectory
BuiltModuleSubdirectory = $BuiltModuleSubdirectory

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we need to only pass BuiltModuleSubdirectory to Get-SamplerWorkspaceLinkedModuleRoot if it is a bound parameter. Otherwise this will pass empty string to the function and the function will go down another codepath than today. If not passing the parameter if it is null or empty string then the default value for the parameter in the function becomes 'module' which then will move into same code pah as today. 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Set-SamplerTaskVariable -AsNewBuild runs before this call and is dot-sourced into the task scope. When BuiltModuleSubdirectory is unset, it resolves the value to the absolute output root, so this call does not pass an empty string.

I verified both paths:

  • passing the resolved value uses output, matching the path added to
    PSModulePath by build.ps1;
  • omitting the parameter uses the helper's module default and produces
    output\module.

I also verified that Import-Module <Name> succeeds when the link is directly under output, but fails when it is under output\module while only output is on PSModulePath. Therefore I think the resolved value must continue to be passed through. I agree this dependency is not obvious, so adding a focused test for the value passed to the helper would make the intent clearer.

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.

BuiltModuleSubdirectory default in the WorkspaceDependencies` task leaks into all tasks and breaks projects that do not set it

2 participants