Vscode-powershell: #Requires with hashtable marked as invalid.

Created on 7 May 2018  路  6Comments  路  Source: PowerShell/vscode-powershell

System Details

  • Operating system name and version: Windows 10 1709
  • VS Code version: 1.23.0
  • PowerShell extension version: 1.7.0
PS X:\git\github\EditorSyntax> code -v

1.23.0
7c7da59c2333a1306c41e6e7b68d7f0caa7b3d45
x64

PS X:\git\github\EditorSyntax> $pseditor.EditorServicesVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
1      7      0      0

PS X:\git\github\EditorSyntax> code --list-extensions --show-versions

[email protected]
[email protected]
[email protected]
[email protected]

PS X:\git\github\EditorSyntax> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.16299.251
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.251
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

When using #Requires -Modules with a hashtable (valid per https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_requires):

Requires -Modules PSWorkflow @{
  ModuleName="PSScheduledJob"
  ModuleVersion="1.0.0.0"
}

The hashtable is marked as invalid within VS Code:

Cannot process the #requires statement because it is not in the correct format.
The #requires statement must be in one of the following formats:
 "#requires -shellid <shellID>"
 "#requires -version <major.minor>"
 "#requires -psedition <edition>"
 "#requires -pssnapin <psSnapInName> [-version <major.minor>]"
 "#requires -modules <ModuleSpecification>"
 "#requires -runasadministrator"

hashtable-requires

Most helpful comment

@rkeithhill, that was a copy paste directly from about_requires. If it cannot be multi-line I will submit a documentation issue to Microsoft.

All 6 comments

What version of PSSA is getting loaded into the integrated console. You should be able to check this with:

(Get-Runspace 4).CreatePipeline("gmo psscriptanalyzer").Invoke()

@rkeithhill 1.16.1

OK, that message is coming from PSScriptAnalyzer but in this case it is correct. A #Requires is a special line comment. It can't span multiple lines. Try using this instead:

#Requires -Modules PSWorkflow,@{ModuleName="PSScheduledJob"; ModuleVersion="1.0.0.0"}

@rkeithhill, that was a copy paste directly from about_requires. If it cannot be multi-line I will submit a documentation issue to Microsoft.

I'm ~90% sure that's a doc bug.

@rkeithhill, fair enough. I have honestly never tried. Just working on the EditorSyntax repo. Will submit a doc bug report.

Was this page helpful?
0 / 5 - 0 ratings