"Import-Module MSOnline" not working when packaging via project build function in Visual Studio
Create a new project in Visual Studio with this simple script:
Script.ps1
Import-Module MSOnline
Write-Host "End."
Now enable packaging in project settings and build via the respective function e.g. by pressing Ctrl + B. Also package the script by right clicking on it and executing "Package as executable".
Now open a new PS console and execute the two resulting executables.
Result when packaging by right click:
End.
Result when building the whole project:
Import-Module : Die Datei oder Assembly "file:///C:\Program
Files\WindowsPowerShell\Modules\MSOnline\1.1.183.57\Microsoft.Online.Administration.Automation.PSModule.dll" oder eine
Abhängigkeit davon wurde nicht gefunden. Es wurde versucht, eine Datei mit einem falschen Format zu laden.
In Zeile:5 Zeichen:1
+ Import-Module MSOnline
+ ~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Import-Module], BadImageFormatException
+ FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
End.
This has been verified on two different systems.
Visual Studio 2019: Version 16.4.3 PoshTools: Version 5.3.2
Output of $PSVersionTable:
Name Value ---- ----- PSVersion 5.1.17763.771 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.17763.771 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1