在工作中,我们正在使用 VSCode、PowerShell 扩展和 PSScriptAnalyzer 开发 PowerShell 解决方案。我们的文件被定义为包含类的 .psm1
文件,并使用 using module
使用相对路径导入其他 .psm1
文件。
问题是,using module
似乎不支持智能感知,即 PowerShell 解析器无法静态分析:This can also be due the type not being known at parse time due to types imported by 'using' statements. PSScriptAnalyzer(TypeNotFound)
我想知道是否有办法使用相对路径导入其他模块,同时仍然支持智能感知。
理想情况下,这会发生在 .psm1
文件本身中,以减少新开发人员的设置时间,但我可以使用其他设置步骤,即将它们添加到 $env:PSModulePath
。
现在文件的结构如下:
# ./BaseClass.psm1
class BaseClass {
# ...
}
# ./SomeClass.psm1
using module .\BaseClass.psm1
class SomeClass : BaseClass {
# ...
}