如果我使用嵌套模块创建清单模块,则在第一个之后的所有嵌套模块中的导出函数不会出现在可用命令列表中,并且不会触发模块自动加载.
当我运行"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 = ''
}
Run Code Online (Sandbox Code Playgroud)
第1单元(Build\Build.psm1)
function Update-LegacyServices()
{
echo "Update"
}
Export-ModuleMember -Function Update-LegacyServices
Run Code Online (Sandbox Code Playgroud)
第2单元(database\Database.psm1)
Function Get-Backup($directory, $name)
{
echo "Get-Backup"
}
Export-ModuleMember -Function Get-Backup
Run Code Online (Sandbox Code Playgroud)
我的 .psd1 文件中有这一行
FunctionsToExport = 'FuncFromMainPsm1 FuncFromSecondPsm1'
Run Code Online (Sandbox Code Playgroud)
这是我从 Powershell Tools for Visual Studio 生成的行中推断出的:
# Functions to export from this module
FunctionsToExport = '*'
Run Code Online (Sandbox Code Playgroud)
这导致我Get-Module -ListAvailable展示了看起来正确的东西
Script 1.0 MyMModule FuncFromMainPsm1 FuncFromSecondPsm1
Run Code Online (Sandbox Code Playgroud)
但是当我打电话时,FuncFromSecondPsm1我会收到“术语‘FuncFromSecondPsm1’无法识别......”。
所以我将导出行更改为
FunctionsToExport = @('FuncFromMainPsm1', 'FuncFromSecondPsm1')
Run Code Online (Sandbox Code Playgroud)
现在一切正常了。我可以在模块加载后调用这两个函数,无论是通过 autoload 还是Import-Module.
我已经尝试过使用和不使用两者ModuleList并FileList设置。它们没有什么区别。
| 归档时间: |
|
| 查看次数: |
5407 次 |
| 最近记录: |