我可以运行一个.NET程序集code在命令行? [英] Can I run code from a .NET assembly from a command line?

查看:177
本文介绍了我可以运行一个.NET程序集code在命令行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.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

这篇关于我可以运行一个.NET程序集code在命令行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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