如果我使用嵌套模塊創建了清單模塊,則在第一個模塊之後的所有嵌套模塊中導出的函數不會出現在可用命令列表中,不會觸發模塊自動加載。在腳本模塊中調用嵌套模塊中的函數並不總是觸發模塊自動加載
當我運行「Get-Module-ListAvailable」時,它們也不會出現。
只有從第一個嵌套模塊導出的函數出現在命令列表中。
如果我明確導入模塊,則所有導出的函數都可用。
在下面的示例中,Update-LegacyServices在顯式導入模塊之前不可用。
我可以使它工作的唯一方法是將我的模塊文件重命名爲以ps1而不是psm1結尾,並將它們包含在ScriptsToProcess中,這似乎是一個糟糕的主意。
模塊清單(PSD1)
@{
# Script module or binary module file associated with this manifest.
# RootModule = ''
# Version number of this module.
ModuleVersion = '1.0.0.1'
# ID used to uniquely identify this module
GUID = 'c11d6aca-d531-4d06-a732-5fb95113357f'
# Author of this module
Author = 'luke'
# Company or vendor of this module
CompanyName = ''
# Copyright statement for this module
Copyright = ''
# Description of the functionality provided by this module
# Description = 'MyBudget Developer Powershell Module'
# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '4.0'
# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''
# Minimum version of the Windows PowerShell host required by this module
# PowerShellHostVersion = ''
# Minimum version of the .NET Framework required by this module
DotNetFrameworkVersion = '4.5.0'
# Minimum version of the common language runtime (CLR) required by this module
CLRVersion = '4.0.30319.18444'
# Processor architecture (None, X86, Amd64) required by this module
# ProcessorArchitecture = ''
# Modules that must be imported into the global environment prior to importing this module
RequiredModules = 'BitsTransfer'
# Assemblies that must be loaded prior to importing this module
# RequiredAssemblies = @()
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
ScriptsToProcess = @()
# Type files (.ps1xml) to be loaded when importing this module
# TypesToProcess = @()
# Format files (.ps1xml) to be loaded when importing this module
# FormatsToProcess = @()
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
NestedModules = @('database\Database.psm1', 'build\Build.psm1')
# Functions to export from this module
#FunctionsToExport = '*'
# Cmdlets to export from this module
CmdletsToExport = '*'
# Variables to export from this module
VariablesToExport = '*'
# Aliases to export from this module
AliasesToExport = '*'
# List of all modules packaged with this module.
ModuleList = @('database\Database.psm1', 'build\Build.psm1')
# List of all files packaged with this module
# FileList = @()
# Private data to pass to the module specified in RootModule/ModuleToProcess
# PrivateData = ''
# HelpInfo URI of this module
# HelpInfoURI = ''
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
# DefaultCommandPrefix = ''
}
模塊1(構建\ Build.psm1)
function Update-LegacyServices()
{
echo "Update"
}
Export-ModuleMember -Function Update-LegacyServices
模塊2(數據庫\ Database.psm1)
Function Get-Backup($directory, $name)
{
echo "Get-Backup"
}
Export-ModuleMember -Function Get-Backup
我想你必須從模塊清單中取消註釋'#FunctionsToExport ='*''。 – 2014-10-08 07:29:43
你認爲還是你測試過?對我而言都沒有效果 – LukeN 2014-10-08 07:37:48
正如我所說,我想。只是一種預感。如果它不起作用,那就這樣吧。 – 2014-10-08 07:42:25