-
Notifications
You must be signed in to change notification settings - Fork 395
Invoke-ScriptAnalyzer do not load the required modules declared in a module manifest #599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@LaurentDardenne Can you please elaborate on this issue a bit more. If you can provide me the steps and files to reproduce this error that would be very helpful as well. Thanks! |
Here is an archive containing both modules. |
@LaurentDardenne Thanks for the information. Looks like even though Log4Posh is specified in the RequiredModules field in the manifest of ParameterSetRules module, it is not being imported when Invoke-ScriptAnalyzer imports ParameterSetRules module for running the custom rule. PS> gc -Path C:\temp\test.txt
TEST RequiredModule
DebugLogger -is null : True
Microsoft.PowerShell.Management,Microsoft.PowerShell.Utility,ParameterSetRules Importing ParameterSetRules through command line though imports the RequiredModules PS> Get-Module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con...
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Script 1.1 PSReadline {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-PS...
PS> Import-Module .\ParameterSetRules -Verbose
VERBOSE: Loading module from path
'C:\temp\Issue-With-RequiredModule\ParameterSetRules\ParameterSetRules.psd1'.
VERBOSE: Loading module from path
'C:\temp\Issue-With-RequiredModule\ParameterSetRules\ParameterSetRules.psm1'.
VERBOSE: Importing function 'Measure-DetectingErrorsInDefaultParameterSetName'.
PS> Get-Module
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.2.0.0 Log4Posh {ConvertTo-Log4NetCoreLevel, Get-DefaultAppenderFileName, ...
Manifest 3.1.0.0 Microsoft.PowerShell.Management {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Con...
Manifest 3.1.0.0 Microsoft.PowerShell.Utility {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Script 0.0.0.1 ParameterSetRules Measure-DetectingErrorsInDefaultParameterSetName
Script 1.1 PSReadline {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-PS...
Script 1.6.0 PSScriptAnalyzer {Get-ScriptAnalyzerRule, Invoke-ScriptAnalyzer} This looks like some kind of bug. |
Same problem with the key 'RequiredAssemblies', the assemblies declared are not loaded : RequiredAssemblies = @('System.Data.Entity.Design','System.Globalization') Module code : #$DebugLogger.PSDebug("$([System.AppDomain]::CurrentDomain.GetAssemblies().Location|out-string)")
$script:PluralSrvc =[System.Data.Entity.Design.PluralizationServices.PluralizationService]::CreateService(([System.Globalization.CultureInfo]::GetCultureInfo("en-us")))
$DebugLogger.PSDebug("is `$script:PluralSrvc null: $($null -eq $script:PluralSrvc)") # -> True WorkAround : use Add-Type inside the module code. Add-Type -AssemblyName System.Data.Entity.Design,System.Globalization
$script:PluralSrvc =[System.Data.Entity.Design.PluralizationServices.PluralizationService]::CreateService(([System.Globalization.CultureInfo]::GetCultureInfo("en-us")))
$DebugLogger.PSDebug("is `$script:PluralSrvc null: $($null -eq $script:PluralSrvc)") # -> False |
For a script module, the scriptblock assigned to $MyInvocation.MyCommand.ScriptBlock.Module.OnRemove is not called. |
The module manifest does not seem loaded :

The text was updated successfully, but these errors were encountered: