如何在 Linux 上发布 Powershell 模块?

如何在 Linux 上发布 Powershell 模块?

目前我得到了

PS /data/projects/lesspass-powershell> Publish-Module -Name "Lesspass" -Repository PSGallery -NuGetApiKey xxxxxxxxxxxxxxxxxxxx
Publish-Module : The specified module 'Lesspass' was not published because no module with that name was found in any module directory.
At line:1 char:1
+ Publish-Module -Name "Lesspass" -Repository PSGallery -NuGetApiKey oy ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (Lesspass:String) [Publish-Module], ArgumentException
+ FullyQualifiedErrorId : ModuleNotAvailableLocallyToPublish,Publish-Module

项目布局

我的项目$HOME/projects/lesspass-powershell

❯ tree
.
├── Lesspass-Clipboard.psm1
├── Lesspass-Clipboard.tests.ps1
├── Lesspass-Password.psm1
├── Lesspass-Password.tests.ps1
├── Lesspass-Profile.psm1
├── Lesspass-Profile.tests.ps1
├── Lesspass.psd1
├── Lesspass.psm1
├── Lesspass.tests.ps1
├── Lesspass-Validator.psm1
├── Lesspass-Validator.tests.ps1
├── LICENSE
├── makefile
├── PBKDF2_HMAC.cs
└── README.md

问题

如何从我当前的工作目录发布模块?

答案1

  1. 我将项目目录重命名Lesspass必须与您要发布的模块相同
  2. 将我的项目目录添加到$Env:PSModulePath

    $Env:PSModulePath = $Env:PSModulePath + ":$HOME/projects/lesspass-powershell"
    
  3. 然后发布

    Publish-Module `
        -Name "Lesspass" `
        -Repository "PSGallery" `
        -NuGetApiKey $Env:PSGALLERY_API_KEY `
    

可选

Lesspass-为了清楚起见,重命名文件以删除前缀

❯ tree
.
├── Clipboard.psm1
├── Clipboard.tests.ps1
├── Lesspass.psd1
├── Lesspass.psm1
├── Lesspass.tests.ps1
├── LICENSE
├── makefile
├── Password.psm1
├── Password.tests.ps1
├── PBKDF2_HMAC.cs
├── Profile.psm1
├── Profile.tests.ps1
├── README.md
├── tools
│   └── publish-module.ps1
├── Validator.psm1
└── Validator.tests.ps1

答案2

您可以从任何您想要的目录发布。PSD1 将定义模块名称。如果您在模块目录之外进行开发(您应该这样做),请指定Path以下内容Name

$publish = @{
  Path = "$HOME/projects/lesspass-powershell"
  Repository = 'PSGallery'
  NuGetApiKey = $env:PSGALLERY_API_KEY
}

Publish-Module @publish

相关内容