在 powershell 2.0 中添加对 dll 的引用 [英] Add reference to dll in powershell 2.0
本文介绍了在 powershell 2.0 中添加对 dll 的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 C# 中创建了一个 dll,并想在 PowerShell 中使用它.
I created a dll in C# and would like to use it in PowerShell.
我知道我可以使用以下方法加载 dll:
I know I can load the dll using:
[Reflection.Assembly]::LoadFile("MyDll.dll")
但我不想使用反射.
有没有一种简单的方法可以在没有反射的情况下包含我的 dll?像添加对这个 dll 的引用?
Is there a simple way to do include my dll without reflection? Something like add reference to this dll?
推荐答案
在 PowerShell 2.0 中,cmdlet Add-Type
就是为此而设计的,例如:
In PowerShell 2.0 the cmdlet Add-Type
is designed for this, for example:
Add-Type -Path "$env:Xyz\bin\Npgsql.dll"
(它更有可能在幕后调用相同的 LoadFile
,但这种方式更像 PowerShell)
(it’s more likely that under the covers it calls the same LoadFile
but this way is more PowerShell-ish)
这篇关于在 powershell 2.0 中添加对 dll 的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文