Set-PSResourceRepository fails on first run when PSResourceGet store directory does not exist

未关闭
#1,965 2 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@alerickson 已经在做这个了。

开始于 2026年8月13日。

评估

这个 Issue 还没有评估数据。

描述

Area-PSRepository
Prerequisites
  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.
Steps to reproduce

On a fresh Linux environment where the PSResourceGet store directory does not exist, run the following:

Import-Module Microsoft.PowerShell.PSResourceGet
Remove-Item -Recurse -Force /home/vscode/.local/share/PSResourceGet -ErrorAction SilentlyContinue
Set-PSResourceRepository -Name PSGallery -Trusted

I also encountered this during a brand new GitHub Codespaces/devcontainer build, where postCreateCommand runs Set-PSResourceRepository -Name PSGallery -Trusted. A minimal first-run repro is enough to trigger the same problem

Observed notes:

  • Get-PSResourceRepository can return the default PSGallery repository.
  • Set-PSRepository -Name PSGallery -InstallationPolicy Trusted does not fail in the same environment.
  • Creating the parent directory manually makes the PSResourceGet command succeed:
    mkdir -p /home/vscode/.local/share/PSResourceGet
    
    After that, this succeeds:
    Set-PSResourceRepository -Name PSGallery -Trusted
    
Expected behavior
Set-PSResourceRepository should succeed on first run and create any missing parent directory or repository store file needed for PSResourceGet state.
Actual behavior
Set-PSResourceRepository fails before it can initialize the repository store:

Cannot retrieve the dynamic parameters for the cmdlet. Loading repository store failed: Could not find a part of the path '/home/vscode/.local/share/PSResourceGet/PSResourceRepository.xml'.


In the devcontainer build log, the same failure aborts postCreateCommand entirely:

2026-03-19 02:43:19.647Z: Running the postCreateCommand from devcontainer.json...
2026-03-19 02:43:19.647Z: pwsh .devcontainer/install-dev-tools.ps1 && bash ./.devcontainer/workspace-repositories-clone.sh
2026-03-19 02:43:20.940Z: Set-PSResourceRepository: /workspaces/excloud-runbooks-ghemu/.devcontainer/install-dev-tools.ps1:5
Line |
   5 |  Set-PSResourceRepository -Name PSGallery -Trusted
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot retrieve the dynamic parameters for the cmdlet. Loading
     | repository store failed: Could not find a part of the path
     | '/home/vscode/.local/share/PSResourceGet/PSResourceRepository.xml'.
2026-03-19 02:43:21.041Z: postCreateCommand from devcontainer.json failed with exit code 1. Skipping any further user-provided commands.
Error details
PSMessageDetails      : 
Exception             : System.Management.Automation.ParameterBindingException:
                         Cannot retrieve the dynamic parameters for the 
                        cmdlet. Loading repository store failed: Could not 
                        find a part of the path '/home/vscode/.local/share/PSRe
                        sourceGet/PSResourceRepository.xml'.
                         ---> System.Management.Automation.PSInvalidOperationEx
                        ception: Loading repository store failed: Could not 
                        find a part of the path '/home/vscode/.local/share/PSRe
                        sourceGet/PSResourceRepository.xml'.
                           at Microsoft.PowerShell.PSResourceGet.UtilClasses.Re
                        positorySettings.Read(String[] repoNames, String[]& 
                        errorList) in C:\__w\1\s\PSResourceGet\src\code\Reposit
                        orySettings.cs:line 603
                           at Microsoft.PowerShell.PSResourceGet.Cmdlets.SetPSR
                        esourceRepository.GetDynamicParameters() in C:\__w\1\s\
                        PSResourceGet\src\code\SetPSResourceRepository.cs:line 
                        112
                           at System.Management.Automation.CmdletParameterBinde
                        rController.HandleCommandLineDynamicParameters(Paramete
                        rBindingException& outgoingBindingException)
                           --- End of inner exception stack trace ---
                           at System.Management.Automation.ExceptionHandlingOps
                        .CheckActionPreference(FunctionContext funcContext, 
                        Exception exception)
                           at System.Management.Automation.Interpreter.ActionCa
                        llInstruction`2.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTry
                        CatchFinallyInstruction.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTry
                        CatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject          : 
CategoryInfo          : InvalidArgument: (:) [Set-PSResourceRepository], 
                        ParameterBindingException
FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.PSRe
                        sourceGet.Cmdlets.SetPSResourceRepository
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}
Environment data
ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     1.2.0                 Microsoft.PowerShell.PSResourceGet  {Compress-PSResource, Find-PSResource, Get-InstalledPSResource, Get-PSResourceRepository…}

Name                           Value
----                           -----
PSVersion                      7.6.0
PSEdition                      Core
GitCommitId                    7.6.0
OS                             Ubuntu 24.04.4 LTS
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Visuals

No response

主要语言
C#
星标
576
派生
114
平均合并
23 小时 17 分钟
30 天内合并 PR
8

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

PowerShell/PSResourceGet 的其他 Issue

查看 PowerShell/PSResourceGet 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。