【发布时间】:2016-12-18 12:11:32
【问题描述】:
如何使用Add-Type 添加带有System.Windows.Forms 命名空间的C# 代码?
我试过这个命令:
Add-Type -TypeDefinition @"
using System;
using System.Windows.Forms;
namespace testnamespace
{
public static class testclass
{
public static string messagebox()
{
MessageBox.Show("test")
return "test";
}
}
}
"@
但我收到一些错误,例如:
命名空间“System.Windows”中不存在类型或命名空间名称“Forms”(您是否缺少程序集引用?)
我只想在 PowerShell 中使用 ONLY C# 代码。请不要给我其他选择。
【问题讨论】:
-
使用菜单项目:添加新项目:Windows 窗体。它会自动在一个新类中设置所有内容。
标签: c# .net powershell powershell-2.0