Powershell DLL加载 [英] Powershell dll loading

查看:207
本文介绍了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("$automationHome\dll\abc.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,Version = 1.0.0.0,
文化=中性,PublicKeyToken =空或其依赖项之一。
系统找不到指定的文件。

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.dll abc.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天全站免登陆