从How to Write a PowerShell Module Manifest-PowerShell中,我了解到我可以使用VariablesToExport = '*'
.
但是,使用后发现无法导出任何变量。
在编写测试以确认并阅读更多文档后,我没有找到问题的原因。我可能忽略了一些重要的事情。
这里发生了什么?
# TestModule.psm1 excerpt:
0..9 | ForEach-Object { New-Variable -Name "v_$_" -Value $_ }
# TestModule.psd1 excerpt:
@{ModuleVersion = '1.0';RootModule = 'TestModule.psm1';VariablesToExport = '*'}
# TestModule.Tests.ps1(Module has been imported)
# Confirm that the module has indeed been imported.
$ModuleName | Get-Module | ForEach-Object 'name' | Should -Be $ModuleName
# All variables do not exist.
0..9 | ForEach-Object { "variable:v_$_" | Test-Path | Should -BeFalse }