PSDepend

PowerShellOrgMIT活跃维护

PowerShell 模块依赖管理器,用声明式配置文件统一拉取和安装构建、CI 流程所需的模块版本,解决脚本环境依赖不一致的问题。

PowerShell Dependency Handler

0.6.0发布于 2026-09-30 20:48 UTC314star81fork同步于 2026-11-10 06:04 UTC

怎么上手

README 里没有找到可直接复制的安装命令

README 里没有找到可直接复制的安装命令,请到 README 或官方文档查看安装方式。

硬件要求

README 没有说明硬件要求。

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

这个项目的说明还在生成中,先参考下面「最近发版」和 README。

最近发版

5 个版本0.6.0
  1. 0.7.0-beta1Release 0.7.0-beta1pre-release2026-10-07 · 2026-10-07 03:08 UTC
    查看更新说明

    Added

    • npm-style lock files. Update-PSDependLock resolves supported Dependencies and their transitive dependencies to exact versions in <name>.lock.json. Invoke-PSDepend and Get-Dependency honor locks automatically, install transitive packages first, preserve separate root installation contexts, reject malformed or unsafe lock data, and detect changes to Dependencies, versions, resolution sources, and DependencyScript parameters. -IgnoreLock opts out. Resolution is greedy and does not backtrack to older parent versions.
    • New Resolve PSDependAction for PSGalleryModule, PSResourceGet, PSGalleryNuget, Nuget, Chocolatey and Npm: query the source and return an exact version without installing. Npm accepts npm semver ranges and pins only the declared package; its subtree remains under npm's package-lock.json.

    Fixed

    • Invoke-DependencyScript -PSDependTypePath is now passed through to the type/script lookup instead of always reading the module's PSDependMap.psd1.
    • Lock resolution now exhausts paged NuGet v2 feeds, honors exact prerelease requests, rejects ambiguous framework-specific dependency constraints, and re-resolves whenever a combined constraint changes so the highest matching version remains locked.
  2. 0.6.0Release 0.6.0最新正式版2026-09-30 · 2026-09-30 20:48 UTC

    Added

    • NuGet version-range support for Chocolatey dependencies. Ranges resolve to the highest matching package version before installation.

    Fixed

    • Build initialization now explicitly loads the pinned Pester 5 version before importing PowerShellBuild and uses a Pester 5-compatible test task, preventing a newer installed Pester version from being loaded.
  3. 0.5.0Release 0.5.02026-08-17 · 2026-08-17 04:49 UTC
    查看更新说明

    Added

    • Version ranges in the Version field using NuGet range syntax (e.g. '[2.2.3,3.0)', '[2.0,)', '(,3.0)') for the PSGalleryModule, PSResourceGet, and PSGalleryNuget dependency types. A bare version (e.g. '3.2.1') still means that exact version; a range installs the highest available version that satisfies it (#65, #91, #199).
    • FileDownload is now supported on all platforms (windows, core, macos, linux); there was no Windows-only code blocking this (#98, #193).
    • FileDownload relative Target paths are now rooted against $PWD before resolution, matching the intuitive expectation of callers (#49, #193).

    Fixed

    • Get-Dependency -InputObject no longer mutates the caller's hashtable: PSDependOptions is now preserved after the call, so a second invocation with the same object still honors global options such as Target (#35, #192).
    • FileDownload no longer misidentifies a directory-like Target (no file extension, or trailing slash) as a full file path when its parent happens to exist; the handler now uses a file-extension heuristic to distinguish file targets from container targets and creates the directory when it does not yet exist (#49, #193).
    • Git handler no longer silently ignores a pre-existing directory at the clone target that is not a valid git repository; it now emits a Write-Warning so the user knows why the install was skipped (#86, #194).
  4. 0.4.1Release 0.4.12026-06-12 · 2026-06-12 22:47 UTC
    查看更新说明

    Added

    • Reviewer checklist guidance for dependency scripts covering external tool/endpoint currency (version-gating CLI flags across tool majors), docs-vs-code drift, secrets on process command lines, and output-stream hygiene — the blind spots that let #187 ship (#189).

    Changed

    • GitHub zip extraction now uses Expand-Archive instead of the COM shell.application API, which failed on Server Core and other non-interactive sessions; the module floor is PS 5.1, where Expand-Archive is always available (#189).

    Fixed

    • Chocolatey handler is now compatible with Chocolatey 2.x: remote version queries use choco search (in 2.0, choco list stopped querying remote sources and rejects URL sources), and --local-only is passed only on 1.x, where it still exists, based on detection of the installed CLI version (#187, #189).
    • Chocolatey default feed and bootstrap script URLs updated to community.chocolatey.org; fixed an undefined variable in the bootstrap error path and switched version checks to typed comparison so prerelease versions no longer throw or trigger reinstalls (#189).
    • PSGalleryNuget "have latest" check compared version strings lexically, so 10.0.0 sorted below 9.0.0 and triggered needless reinstalls; it now uses typed SemVer/Version comparison (#189).
    • FileSystem missing-source errors were silenced by an operator precedence bug, and the documented Force / Mirror parameters were absent from the param block, so passing them was a binding error. Force is now wired: it overwrites target files even where the target copy is newer (#189).
    • Task only read Source while its help documented Target, so the documented usage silently ran zero tasks; both are now honored (#189).
    • Git handler stops after reporting that git is not installed instead of attempting to invoke it anyway (#189).
    • Command verbose output referenced the wrong loop variable when processing multiple dependencies (#189).
    • Help tests now iterate parameters correctly during Pester discovery and use the right variable names in assertions.
  5. 0.4.0-alphaRelease 0.4.0-alphapre-release2026-05-26 · 2026-05-26 22:50 UTC
    查看更新说明

    Added

    • PSResourceGet dependency type providing first-class support for PowerShellGet v3 (Microsoft.PowerShell.PSResourceGet) alongside the existing PSGalleryModule handler (#179).
    • InstallLocal psake task that stages files and installs the module to CurrentUser scope from Output\, useful for validating pre-release bits locally without publishing (#180).
    • Chocolatey dependency type with handler script and Pester coverage, enabling Chocolatey packages alongside PowerShell modules in requirements.psd1.
    • Nuget dependency type for arbitrary NuGet feeds (not just the PowerShell Gallery), including custom DLL name support and the ability to extract .exe payloads.
    • Credential support across PSGalleryModule, PSGalleryNuget, and Invoke-PSDepend, including credentialed NuGet feed search and a warning when credential configuration looks wrong.
    • Core, macOS, and Linux platform tags on Nuget in PSDependMap.psd1, enabling cross-platform use.
    • SemVer / prerelease handling for module versions, with a PowerShell version guard so PSDepend's SemanticVersion does not collide with the native System.Management.Automation.SemanticVersion class in PS 6+; falls back to System.Version when a version string is not SemVer-compatible.
    • AcceptLicense parameter on PSRepositoryModule and matching AcceptLicense + AllowPrerelease plumbing on PSGalleryModule, splatted only when explicitly specified to preserve compatibility with older PowerShellGet versions.
    • Stale workflow (.github/workflows/stale.yml) for issues and PRs, with a workflow_dispatch trigger for on-demand sweeps.
    • CONTEXT.md documenting the PSDepend domain lexicon (Dependency, DependencyType, Target, Scope, PSDependAction, etc.) for both human and AI contributors.

    Changed

    • Migrated the entire Pester test suite from v4 to v5 (#164), including new Pester v5 unit tests for individual dependency-type handler scripts and a reviewer checklist documenting the migration conventions (#166).
    • Build system rewritten on top of PowerShellBuild with GitHub Actions replacing the prior AppVeyor pipeline (#163); CI workflow actions were updated to current major versions across the board (#168).
    • Test bootstrap now runs through build.ps1 (Bootstrap / StageFiles / Test) rather than ad-hoc setup, so tests always import from Output\ and not the source tree (#171). See CLAUDE.md for the contract.
    • FunctionsToExport in PSDepend.psd1 is now an explicit list of the eight public commands instead of *, matching PowerShell module guidance and improving discoverability.
    • NuGet command-line bootstrap is now lazy: it runs only when a Nuget or PSGalleryNuget dependency is actually used, instead of on every module import (#175).
    • Default branch references updated from master to main across README, examples, the manifest's LicenseUri / ProjectUri / ReleaseNotes links, and build/CI scripts.
    • README and example dependency files updated to reflect the PowerShellOrg ownership of the project.
    • Github dependency type now allows overriding the imported name via the standard Name key, instead of always deriving it from the owner/repo slug (#121).
    • Github version matching now accepts a vX.Y.Z tag when the dependency requests X.Y.Z, so dependencies written without the v prefix resolve against the common GitHub release-tag convention (#123).
    • PSGalleryModule may now be invoked without an explicit Repository, in which case PSDepend defers to whatever repositories are currently registered via Get-PSRepository rather than forcing the PowerShell Gallery.

    Fixed

    • Get-Dependency operator-precedence bug when DependencyType is set inside PSDependOptions: parenthesization was incorrect, so the global default failed to apply to dependencies without an explicit type (#131, #173).
    • Find-PSDependLocally n

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    CI

    PSDepend

    PSDepend is a PowerShell dependency handler. Define your dependencies in a simple .psd1 file and let Invoke-PSDepend install them — similar to pip install -r requirements.txt or bundle install.

    Installing

    # PowerShell 7+ (recommended)
    Install-PSResource PSDepend
    
    # PowerShell 5.1
    Install-Module PSDepend
    
    # Manual
    # Download and unblock the repository zip, then extract the PSDepend folder
    # to a module path (e.g. $env:USERPROFILE\Documents\WindowsPowerShell\Modules\)
    

    Quick Start

    Import-Module PSDepend
    Get-Command -Module PSDepend
    Get-Help about_PSDepend
    

    Defining Dependencies

    Store dependencies in a PowerShell data file named *.depend.psd1 or requirements.psd1. Invoke-PSDepend will find these files automatically.

    Simple syntax

    @{
        psake        = 'latest'
        Pester       = 'latest'
        BuildHelpers = '0.0.20'
        PSDeploy     = '0.1.21'
    
        'PowerShellOrg/PSDepend' = 'main'
    }
    

    PSDepend infers PSGalleryModule for bare names and GitHub for owner/repo entries:

    DependencyName          DependencyType  Version Tags
    --------------          --------------  ------- ----
    psake                   PSGalleryModule latest
    BuildHelpers            PSGalleryModule 0.0.20
    Pester                  PSGalleryModule latest
    PowerShellOrg/PSDepend  GitHub          main
    PSDeploy                PSGalleryModule 0.1.21
    

    You can also specify the dependency type explicitly:

    @{
        'PSGalleryModule::InvokeBuild'       = 'latest'
        'GitHub::PowerShellOrg/PSDepend'     = 'main'
    }
    

    Flexible syntax

    For more control, use the hashtable syntax. You can mix and match styles within the same file:

    @{
        psdeploy = 'latest'
    
        buildhelpers_0_0_20 = @{
            Name = 'buildhelpers'
            DependencyType = 'PSGalleryModule'
            Parameters = @{
                Repository = 'PSGallery'
                SkipPublisherCheck = $true
            }
            Version = '0.0.20'
            Tags = 'prod', 'test'
            PreScripts = 'C:\RunThisFirst.ps1'
            DependsOn = 'some_task'
        }
    
        some_task = @{
            DependencyType = 'task'
            Target = 'C:\RunThisFirst.ps1'
            DependsOn = 'nuget'
        }
    
        nuget = @{
            DependencyType = 'FileDownload'
            Source = 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe'
            Target = 'C:\nuget.exe'
        }
    }
    

    To inspect the full dependency output:

    $Dependency = Get-Dependency \\Path\To\complex.depend.psd1
    $Dependency[2] | Select-Object *
    
    DependencyFile : \\Path\To\complex.depend.psd1
    DependencyName : buildhelpers_0_0_20
    DependencyType : PSGalleryModule
    Name           : buildhelpers
    Version        : 0.0.20
    Parameters     : {Repository,SkipPublisherCheck}
    Source         :
    Target         :
    AddToPath      :
    Tags           : {prod, test}
    DependsOn      : some_task
    PreScripts     : C:\RunThisFirst.ps1
    PostScripts    :
    Raw            : {Version, Name, Tags, DependsOn...}
    

    The following strings are expanded in Target and Source fields: $PWD (or .), $ENV:USERPROFILE, $ENV:TEMP, $ENV:ProgramData, $ENV:APPDATA. Use single quotes or escape the $ to prevent PowerShell from expanding them before PSDepend can: Target = '$PWD\dependencies'.

    Repository Credentials

    For private repositories that require authentication, set a Credential key in the dependency and pass a matching PSCredential object to Invoke-PSDepend:

    @{
        buildhelpers_0_0_20 = @{
            Name = 'buildhelpers'
            DependencyType = 'PSGalleryModule'
            Parameters = @{
                Repository = 'MyPrivateGallery'
            }
            Version = '0.0.20'
            Credential = 'my_gallery'
        }
    }
    
    Invoke-PSDepend -Path C:\requirements.psd1 -Credentials @{ 'my_gallery' = $creds }
    

    The credential key must match between the dependency definition and the hashtable passed to -Credentials.

    Locking Dependencies

    Like npm's package-lock.json, PSDepend can pin every dependency — and the dependencies they pull in — to exact versions so that every machine installs the same thing:

    Update-PSDependLock -Path .\requirements.psd1   # writes requirements.lock.json
    Invoke-PSDepend -Path .\requirements.psd1       # installs the locked versions
    

    Update-PSDependLock asks each dependency type that supports the Resolve action (PSGalleryModule, PSResourceGet, PSGalleryNuget, Nuget, Chocolatey, Npm) for the highest version that satisfies the declared Version and walks that package's own dependencies. The gallery, NuGet, and Chocolatey types accept NuGet ranges; Npm accepts npm semver ranges such as ^1.2.0 or >=1 <2 and rejects NuGet range syntax. Npm pins only the declared package because npm's own package-lock.json governs its subtree.

    One version is locked per DependencyType::Name. Resolution is greedy: after selecting a parent version, PSDepend intersects child constraints but does not backtrack to an older parent version. Narrow the parent's range if an older version is required. Packages reached from roots with different installation contexts are installed once per root.

    Once a lock exists next to a dependency file, Invoke-PSDepend and Get-Dependency use it automatically. Locked transitive packages install first. A changed dependency, version, resolution source, or DependencyScript parameter makes the lock out of date; removing every dependency does too. Pass -IgnoreLock to use the DependencyFile without the lock. With Invoke-PSDepend -Test, locked root and transitive versions are tested.

    Commit the .lock.json alongside the DependencyFile and review lock changes like code. PSDepend validates its structure and exact versions before use, but version 1 does not contain package content hashes.

    The JSON contains lockfileVersion, dependencies, and packages. Root entries record the requested version, DependencyType::Name package key, and a hash of resolution Source/Parameters. Package entries record an exact version and direct dependency ranges. Synthesized transitive Dependency names normally use Name@Version; a #RootName suffix disambiguates a package installed for another root context.

    Dependency types without a Resolve action (Git, GitHub, FileDownload, ...) are recorded in the lock for drift detection but install exactly as declared.

    Getting Help

    Each dependency type may handle standard properties differently and expose its own parameters. Use Get-PSDependType to see what is available:

    Get-PSDependType
    
    DependencyType  Description                                                 DependencyScript
    --------------  -----------                                                 ----------------
    PSGalleryModule Install a PowerShell module from the PowerShell Gallery.    C:\...\PSDepend\PSDepen...
    Task            Support dependencies by handling simple tasks.              C:\...\PSDepend\PSDepen...
    Noop            Display parameters that a depends script would receive...   C:\...\PSDepend\PSDepen...
    FileDownload    Download a file                                             C:\...\PSDepend\PSDepen...
    

    Read the comment-based help for any dependency type:

    Get-PSDependType -DependencyType PSGalleryModule -ShowHelp
    

    Additional help topics:

    Get-Help about_PSDepend
    Get-Help about_PSDepend_Definitions
    Get-Help Get-Dependency -Full
    

    Extending PSDepend

    PSDepend is extensible. To add a new dependency type, create a script in the PSDependScripts folder and register it in PSDependMap.psd1.

    Your script must:

    • Include comment-based help describing how it uses Dependency metadata
    • Accept Install, Test, and Import in PSDependAction; optionally accept Resolve as a fourth action
    • For Resolve, query only and emit one PSDepend.ResolvedDependency with an exact Version and direct Dependencies; do not install

    See Git.ps1 and PSGalleryModule.ps1 for reference implementations.

    Examples

    Contributing

    Contributions are welcome. Please read the PowerShellOrg contributing guide before opening a pull request.

    Acknowledgements

    PSDepend was originally created by Warren Frame (RamblingCookieMonster) and is now maintained by the PowerShellOrg organization.

    The concept was inspired by Michael Willis's PSRequire.