Powershell dll加载 [英] Powershell dll loading

查看:24
本文介绍了Powershell dll加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Powershell 脚本,它调用 C# 库中的一个方法.库 dll 加载为:

I have a Powershell script that calls a method in a C# library. The library dll is loaded as:

[Reflection.Assembly]::LoadFrom("$automationHomedllabc.dll") | Out-Null

现在,我的 C# 库在其中使用了另一个库 xyz.dll.我相信我不需要在 Powershell 脚本中加载它,因为 abc.dll 会解决它.但是,我收到一条错误消息:

Now, my C# library uses another library xyz.dll in it. I believe I don't need to load this in Powershell script, since the abc.dll will resolve it. However, I am getting an error saying:

无法加载文件或程序集 'xyz,版本 = 1.0.0.0,Culture=neutral, PublicKeyToken=null' 或其依赖项之一.这系统找不到指定的文件.

Could not load file or assembly 'xyz, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

谁能告诉我如何解决这个问题?

Can someone please tell me how to fix this?

推荐答案

LoadFrom() 最好在 所在的目录中查找 xyz.dllabc.dll

LoadFrom() should ideally look for the xyz.dll in the same directory as abc.dll

如果您从与 dll 相同的目录运行脚本,请添加以下内容,然后执行 LoadFrom()

If you are running the script from the same directory as the dlls, add the below and then do the LoadFrom()

$currentScriptDirectory = Get-Location
[System.IO.Directory]::SetCurrentDirectory($currentScriptDirectory.Path)

这篇关于Powershell dll加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆