2011-07-25 67 views

回答

10

Here是如何从Powershell加载dll并调用其中的方法的指南。

后的最重要的部分是这些命令:

[C:\temp] 
PS:25 > notepad MyMathLib.cs 

(…) 

[C:\temp] 
PS:26 > csc /target:library MyMathLib.cs 
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42 
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727 
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved. 


[C:\temp] 
PS:27 > [Reflection.Assembly]::LoadFile(“c:\temp\MyMathLib.dll”) 

GAC Version  Location 
— ——-  ——– 
False v2.0.50727  c:\temp\MyMathLib.dll 



[C:\temp] 
PS:28 > [MyMathLib.Methods]::Sum(10, 2) 
12 

[C:\temp] 
PS:29 > $mathInstance = new-object MyMathLib.Methods 
Suggestion: An alias for New-Object is new 

[C:\temp] 
PS:30 > $mathInstance.Product(10, 2) 
20 
+2

比我的链接更好。 =) –

2

是的 - 但您必须拥有一个程序,其中引用该.dll并可以调用它的Main()方法 - 比如说在控制台应用程序中。

相关问题