Sim*_*onS 11 powershell visual-studio-code
我正在使用Visual Studio Code编写我的 PowerShell 脚本。
我已经安装了ms-vscode.powershell
Visual Studio Code的PowerShell 扩展。
每当我在脚本中使用别名时,它都会PSScriptAnalyzer
告诉我使用完整的 CmdLet 名称。这有点烦人,因为它还用绿色曲线标记所有别名。
我怎样才能禁用它?
Sim*_*onS 16
有三种方法可以做到这一点。
选项 1 - 使用搜索功能
>PowerShell: Select PS
然后选择PowerShell: Select PSScriptAnalyzer Rules
PSAvoidUsingCmdletAliases
Confirm
图片:
选项 2 - 完全禁用 ScriptAnalysis
{}
符号"powershell.scriptAnalysis.enable": false
到右侧的用户设置中(请参见下面的屏幕截图)。CTRL + S
截屏:
您的脚本分析器现已禁用,不会再抱怨别名。
选项 3 - 创建设置文件并仅禁用别名信息
"powershell.scriptAnalysis.settingsPath": "C:\\foo\\bar\\FileName.psd1"
并保存这是它的图片:
模板(取自https://github.com/PowerShell/vscode-powershell/blob/develop/examples/PSScriptAnalyzerSettings.psd1):
@{
# Only diagnostic records of the specified severity will be generated.
# Uncomment the following line if you only want Errors and Warnings but
# not Information diagnostic records.
# Severity = @('Error','Warning')
# Analyze **only** the following rules. Use IncludeRules when you want
# to invoke only a small subset of the defualt rules.
IncludeRules = @('PSAvoidDefaultValueSwitchParameter',
'PSMisleadingBacktick',
'PSMissingModuleManifestField',
'PSReservedCmdletChar',
'PSReservedParams',
'PSShouldProcess',
'PSUseApprovedVerbs',
'PSUseDeclaredVarsMoreThanAssigments')
# Do not analyze the following rules. Use ExcludeRules when you have
# commented out the IncludeRules settings above and want to include all
# the default rules except for those you exclude below.
# Note: if a rule is in both IncludeRules and ExcludeRules, the rule
# will be excluded.
ExcludeRules = @('PSAvoidUsingAliases','PSAvoidUsingWriteHost')
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4110 次 |
最近记录: |