导入模块:在PowerShell中无法加载文件或程序集

3
我正在尝试从我的应用程序导入一些 .dll 文件到我的 PowerShell 脚本。有两个 dll 文件:MyProject.dllMyProject.Data.dll。我可以成功加载第一个 dll,我可以访问其中的一个 ENUMS。但问题是当我尝试加载第二个 DLL 时,它会抛出这个错误:

Import-Module : Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

以下是我的脚本内容:
Import-Module "./dll/MyProject.dll"
Import-Module "./dll/MyProject.Data.dll" # error while loading this one.


$global:admin_role = [MyProject.UserRole]::Admin
$global:super_user_role = [MyProject.UserRole]::SuperUser


$user_account = New-Object MyProject.Data.UserAccount

仅供参考,我从MyProject.API/bin/Debug/netcoreapp2.2获取了包含所有dll的文件夹。

1个回答

0

尝试使用Add-Type加载您的dll:

Add-Type -Path .\dll\MyProject.dll
Add-Type -Path .\dll\MyProject.Data.dll

没有参数Type。这是Add-Type包含的内容:Add-Type [-TypeDefinition] <string> [-CodeDomProvider <CodeDomProvider>] [-CompilerParameters <CompilerParameters>] [-Language <Language>] [-ReferencedAssemblies <string[]>] [-OutputAssembly <string>] [-OutputType <OutputAssemblyType>] [-PassThru] [-IgnoreWarnings] [<CommonParameters>] - Ertan Hasani

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接