Skip to content
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ How the module is built.
β”‚ β”œβ”€β”€ formats/ # Formatting metadata registered during build
β”‚ β”‚ β”œβ”€β”€ CultureInfo.Format.ps1xml # Example format included in manifest
β”‚ β”‚ └── Mygciview.Format.ps1xml # Additional format loaded at import
β”‚ β”œβ”€β”€ functions/ # Function scripts exported by the module
β”‚ β”œβ”€β”€ functions/ # Function scripts exported by the module; #Requires -Modules statements here are compiled into RequiredModules
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
β”‚ β”‚ β”œβ”€β”€ private/ # Helper functions scoped to the module
β”‚ β”‚ β”‚ β”œβ”€β”€ Get-InternalPSModule.ps1 # Sample internal helper
β”‚ β”‚ β”‚ └── Set-InternalPSModule.ps1 # Sample internal helper
Expand Down Expand Up @@ -949,10 +949,58 @@ How the module is built.
β”‚ β”‚ └── SolarSystems.ps1 # Example variable surfaced in generated docs
β”‚ β”œβ”€β”€ finally.ps1 # Cleanup script appended to the root module
β”‚ β”œβ”€β”€ header.ps1 # Optional header injected at the top of the module
β”‚ β”œβ”€β”€ manifest.psd1 (optional) # Source manifest reused when present
β”‚ β”œβ”€β”€ manifest.psd1 (optional) # Source manifest reused when present; RequiredModules is not propagated β€” use #Requires -Modules in function files instead (see "Declaring module dependencies" below)
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated
β”‚ └── README.md # Module-level docs ingested by Document-PSModule
```

### Declaring module dependencies

Module dependencies are declared using [`#Requires -Modules`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_requires)
statements at the top of individual PowerShell function files under `src/functions/public/` and `src/functions/private/`.
The build system ([Build-PSModule](https://github.com/PSModule/Build-PSModule)) collects all `#Requires -Modules`
declarations across every source file, de-duplicates them, and writes the merged result into the `RequiredModules` field
of the compiled module manifest.

> [!IMPORTANT]
> Adding `RequiredModules` to `src/manifest.psd1` is **not** supported for this purpose. Those entries are silently
> ignored by the build β€” they will not appear in the built manifest. Use `#Requires -Modules` in function files instead.

#### Supported syntax variants
Comment thread
MariusStorhaug marked this conversation as resolved.
Outdated

```powershell
# Bare module name β€” any version is acceptable
#Requires -Modules Microsoft.Graph.Authentication

# Minimum version constraint
#Requires -Modules @{ ModuleName = 'Microsoft.Graph.Authentication'; ModuleVersion = '2.28.0' }

# Exact version constraint
#Requires -Modules @{ ModuleName = 'PSSemVer'; RequiredVersion = '1.1.4' }
```

#### Example

A function that calls into `Microsoft.Graph.Authentication` declares its dependency at the top of the file:

```powershell
#Requires -Modules @{ ModuleName = 'Microsoft.Graph.Authentication'; ModuleVersion = '2.28.0' }

function Get-GraphToken {
...
}
```

When the module is built, the compiled manifest automatically includes:

```powershell
RequiredModules = @(
@{ ModuleName = 'Microsoft.Graph.Authentication'; ModuleVersion = '2.28.0' }
)
```

This co-location approach keeps dependency declarations next to the functions that need them, making it immediately
clear which commands drive each external dependency.

## Principles and practices

The contribution and release process is based on the idea that a PR is a release, and we only maintain a single linear ancestry of versions, not going
Expand Down
Loading