powershell - 从另一个文件继承一个类
问题描述
你如何从另一个文件继承和使用一个类?
PowerShell version:
$PSVersionTable.PSVersion
Major Minor Patch PreReleaseLabel BuildLabel
----- ----- ----- --------------- ----------
6 2 1
我尝试了以下方法:
# $PWD and $local:PSScriptRoot
# using module ../base/base.psm1
# using module $PWD/../base/base.psm1
# using module ..\base\base.psm1
# using module $PWD\..\base\base.psm1
using module ..\base\base.psm1
Class MyClass : base {
...
}
错误:
Unable to find type [base].PowerShell
Ignoring 'TypeNotFound' parse error on type 'base'. Check if the specified type is correct. This can also be due the type not being known at parse time due to types imported by 'using' statements.PSScriptAnalyzer(TypeNotFound)
解决方案
对于 PS1 文件,只需在行首添加一个点 ( . ):
#LOAD DEV RECIPIES (FUNCTIONS) - not in use (yet)
. "$DeploymentScriptsGitPath\recipies\Recipies-PROD.ps1"
对于 PSM 模块,您需要导入它们:
Import-Module -name c:\work\tools-kit\powershel\modules\sqlserver\ -DisableNameChecking
参考:
get-help import-module -full
推荐阅读
- python - Python十六进制摘要到整数
- php - 无法执行 ALTER TABLE `mydb`.`state1` RENAME TO `state`;没有选择数据库
- amazon-web-services - 如何查看在 AWS 中运行 EC2 实例的代码?
- html - 使 html5 视频 div 可点击并转到超链接
- php - PHP5 zval 容器与 PHP7 zval 容器。现在如何存储引用和变量?
- python - 只允许在 Django Rest Framework 中编辑和不写入字段
- r - 在 table1 包中创建一列 p 值
- html - dangerouslySetInnerHTML html 与发送的 html 不匹配
- sorting - 如何对指数形式数值等数字进行排序
- postgresql - Knex 不返回连接 SQL 查询