Skip to content

Package Config Updates

Purpose

This PowerShell script updates the .NET package configuration block inside the repository's Forge orchestrator YAML (.azdo/templates/forge-orchestrator.yml). It scans the src/dotnet tree for .NET projects, reads the project (.csproj) files, and then regenerates the parameters.dotnet.default.packages section so the YAML reflects the actual project layout and intra-repo dependencies.

Why run this

  • Keep CI/CD configuration in sync with the repository layout, avoiding manual drifts.

  • Ensure package sourceRoot, packagePath, and dependsOn entries are accurate so pipeline orchestration (build/pack/test/publish) targets the correct projects and uses correct dependency ordering.

  • Useful after adding, renaming, or moving .NET projects, or when changing project-to-project references.

When to run

Run the script any time the .NET project structure changes in a way that should be reflected in the orchestrator YAML:

  • New package added under src/dotnet/<PackageName>/src/<PackageName>.csproj

  • A package folder is renamed or moved

  • ProjectReference / PackageReference relationships between repository projects change

  • Preparing a commit that should keep the orchestrator in a deployable state

It is safe to preview changes using the -WhatIf switch which shows the updated package entries without modifying the YAML file.

Where it runs / prerequisites

  • Assumes repository root (script path) and default locations used by the project: src/dotnet for .NET projects and .azdo/templates/forge-orchestrator.yml for the target YAML file.

  • Requires PowerShell (the script is written for pwsh/PowerShell Core and Windows PowerShell).

  • Attempts to install and import the powershell-yaml module for proper YAML parsing. If that fails, the script falls back to a conservative regex-based approach to update the packages section.

How it works (high level)

  1. Validate that the orchestrator YAML and src/dotnet exist. Abort if missing.

  2. Try to install + import powershell-yaml. If successful the script will parse the YAML to extract the existing list of package names. If the module isn't available (or cannot be imported), a regex fallback extracts package names from the expected dotnet section.

  3. For each package name discovered, the script locates the corresponding project folder in src/dotnet/<PackageName> and looks for the main project file named <PackageName>.csproj somewhere under a src subfolder.

  4. It reads the found .csproj as XML and extracts project-to-project references to build a dependsOn list with language dotnet.

  5. Builds a new set of package entries containing name, sourceRoot, packagePath, and optional additionalArguments and dependsOn entries.

  6. Replaces the text between the marker comments # BEGIN[dotnet packages] and # END[dotnet packages] with an updated packages list. If YAML parsing was available the script attempts a slightly safer hybrid replace; otherwise it uses the regex fallback.

Parameters / usage

  • -ForgeOrchestratorPath (string): Path to the forge orchestrator YAML. Defaults to .azdo/templates/forge-orchestrator.yml.

  • -SourceRoot (string): Root directory containing dotnet packages. Defaults to src/dotnet.

  • -WhatIf (switch): Do not write changes; print what would be changed.

Examples

Preview changes without writing:

.\Update-ForgePackageConfig.ps1 -WhatIf

Update the default orchestrator file from a repository root:

.\Update-ForgePackageConfig.ps1

Run against a custom path for testing:

.\Update-ForgePackageConfig.ps1 -ForgeOrchestratorPath ".azdo/templates/forge-orchestrator.yml" -SourceRoot "src/dotnet"

Notes & assumptions

  • Assumes each top-level package maps to a folder named exactly after the package under src/dotnet and that the main project file is named <PackageName>.csproj under a src subfolder. If your layout differs the script may not find the project and will skip that package.

  • The script preserves the rest of the YAML file by surgically replacing only the marked packages block; keep the # BEGIN[dotnet packages] and # END[dotnet packages] markers in place.

Troubleshooting

  • "Forge orchestrator file does not exist": confirm -ForgeOrchestratorPath points to the correct file from the repository root.

  • "Source root does not exist": ensure -SourceRoot points to src/dotnet (or correct location).

  • YAML module installation fails: the script will fall back to a regex-based parser. Ensure you have network access and rights to install powershell-yaml if you prefer the more robust YAML parsing path.

  • Missing package entries after running: check that the package folders and csproj files follow the naming convention the script expects. Inspect the WhatIf output to see what the script discovered.

Suggestions / follow-ups

  • Consider adding a CI validation step that runs the script in -WhatIf mode and fails if the working tree would change — this prevents drift from reaching main branches.

  • If your repo contains packages with different layouts, extend Get-PackageInfoFromProject to locate csproj files with alternative naming patterns.

License

Documentation is provided under the repository's license.