Skip to content

#Requires -Module runs first, even when it's not first line in a script (not doc'd) #694

Closed
@juneb

Description

@juneb

In about_Requires, we need to add a line explaining that this directive runs first in the script, even when it doesn't appear on the first line in the script.

#Requires is supposed to be the first line in the script (as doc'd). But, if it's not, there's no error. Instead, it runs first without warning. Therefore, code like this, in which order matters, fails unexpectedly, because the correct version of the module is imported, then removed.

Get-Module Pester | Remove-Module   #Removes current version
#Requires -Module @{ModuleName = 'Pester'; ModuleVersion = '3.4.3'}
...

Metadata

Metadata

Assignees

Labels

Pri3Priority - Lowarea-languageArea - PowerShell syntax and keywords

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions