[英]Can I make a function acessable that was dot-sourced within an imported-module to the parent script?
I have imported module "ModuleFoo.psm1" to my script: "ModuleBar.ps1" 我已经将模块“ ModuleFoo.psm1”导入我的脚本:“ ModuleBar.ps1”
And I call a method which is in the imported module that does dot sourcing to function BarFunction.ps1: 然后,我在导入的模块中调用一个方法,该方法对功能BarFunction.ps1进行点源:
function Dot-SourceBarFunction()
{
. "\BarFunction.ps1"
}
Can I make this BarFunction.ps1 accessible from the parent scope that is : ModuleBar.ps1? 我是否可以从父范围(即ModuleBar.ps1)访问此BarFunction.ps1?
This should just work eg: 这应该可以正常工作,例如:
-- Outer.ps1 --
Import-Module $PSScriptRoot\module.psm1
Get-Foo
-- Module.psm1 --
. $PSScriptRoot\inner.ps1
-- Inner.ps1 --
function Get-Foo {
"$($MyInvocation.MyCommand.Name) called"
}
This outputs Get-Foo called
. 这将输出
Get-Foo called
。 Functions default to public visibility in modules so when you dot-source the script that pulls in functions within a module, those are automatically made public. 函数默认为模块中的公开可见性,因此,当您在源代码中获取提取模块中函数的脚本时,这些函数将自动公开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.