我有一个.NET类库(如.dll文件)和库中包含的类的静态方法。有没有办法来调用通过命令行方式?
I have a .NET class library (as a .dll file) and that library contains a class with a static method. Is there a way to call that method from a command line?
的这里是如何装入从PowerShell和调用方法一个dll在它的指导。
Here is a guide on how to load a dll from Powershell and call methods in it.
该职位最重要的部分是这些命令:
The most important part of the post are these commands:
[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
上一篇:一个更快的方法来下载多个文件多个、更快、方法来、文件
下一篇:未能从程序集加载类型“ADODB.FieldsToInternalFieldsMarshaler”加载、类型、程序、FieldsToInternalFieldsMarshaler