调用使用PowerShell的Visual Studio的方法 [英] Calling Visual Studio method using powershell
本文介绍了调用使用PowerShell的Visual Studio的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图写一个PowerShell脚本调用多数民众赞成设在我的Visual Studio(2010年)解决方案的方法。 什么是语法要求,例如,像
I am trying to write a powershell script to call a method that's located in my Visual Studio (2010) solution. What is the syntax for calling, for example, a method like
public void CreateData(string s, int i)
推荐答案
您可以编译类库项目到一个DLL,然后在PowerShell中使用反射加载DLL。下面是一个例子:
You can compile your class library project into a dll then load the dll using reflection in powershell. Here is an example:
C#code:
public class MyClass {
public void CreateData(string s, int i) {
// your logic here
}
}
PowerShell的code:
powershell code:
$lib = [Reflection.Assembly]::LoadFile("C:\path\to\MyClass.dll")
$obj = new-object MyClass
$result = $obj.CreateData("s_value",5)
这code假设你的类被称为MyClass的。您可能需要运行设置executionpolicy RemoteSigned就是在PowerShell中第一位。
This code assumes that your class is called "MyClass". You may have to run set-executionpolicy RemoteSigned in powershell first.
这篇关于调用使用PowerShell的Visual Studio的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文