我已经创建了一个PowerShell模块。该模块公开了3个功能。当我在没有清单的情况下直接安装它时,输出将是:
> Import-Module AzureDD
> Get-Module | Where { $_.Name -eq 'AzureDD' }
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 0.0 AzureDD {New-AzureDDAppPermission, New-AzureDDAppRegistration, Sync-AzureDDStorageContainer}
这是因为我在psm文件中的最后一行是:
Export-ModuleMember -Function New-AzureDDAppRegistration, New-AzureDDAppPermission, Sync-AzureDDStorageContainer
现在我想添加版本和更多的元数据,并继续使用
> New-ModuleManifest -Path .AzureDD.psd1 -ModuleVersion "2.0"
其创建新的文件CCD_ 1。在这里我编辑了很多东西。除了其他更改外,我还定义了导出的函数如下:
FunctionsToExport = @('New-AzureDDAppPermission', 'New-AzureDDAppRegistration', 'Sync-AzStorageContainer')
我可以成功测试:
> Test-ModuleManifest .AzureDD.psd1
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 2.0 AzureDD {New-AzureDDAppPermission, New-AzureDDAppRegistration, Sync-AzStorageContainer}
但当我真正导入它时,它不会显示任何导出的命令:
> Import-Module .AzureDD.psd1
> Get-Module | Where { $_.Name -eq 'AzureDD' }
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 2.0 AzureDD
看看与我的第一个片段相比,它是如何变成Manifest
的!在重新导入之前,我已经确保我一直在做Remove-Module AzureDD -Force
。
FunctionsToExport
就像一个筛子-它只是允许嵌套模块通过清单导出其功能,但它们仍然必须在的某个地方定义。
确保将脚本模块(.psm1
文件(指定为清单中的RootModule
(或至少指定为NestedModule
(:
@{
# Script module or binary module file associated with this manifest.
RootModule = 'AzureDD.psm1'
# ...
}