[英]How can I Use Add-Type to add C# code with System.Windows.Forms namespace?
How can I use Add-Type
to add C# code with System.Windows.Forms
namespace? 如何使用
Add-Type
通过System.Windows.Forms
命名空间添加C#代码? I tried this command: 我尝试了以下命令:
Add-Type -TypeDefinition @"
using System;
using System.Windows.Forms;
namespace testnamespace
{
public static class testclass
{
public static string messagebox()
{
MessageBox.Show("test")
return "test";
}
}
}
"@
but I'm getting some error like: 但是我遇到了一些错误,例如:
The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
类型或名称空间名称“ Forms”在名称空间“ System.Windows”中不存在(您是否缺少程序集引用?)
I just want to use ONLY C# code in PowerShell. 我只是想在PowerShell中仅使用C#代码。 Please don't give me alternative.
请不要给我的选择。
Add a reference to the containing assembly (the System.Windows.Forms.dll
file), using the ReferencedAssemblies
parameter: 使用
ReferencedAssemblies
参数添加对包含程序集的引用( System.Windows.Forms.dll
文件):
Add-Type -TypeDefinition @"
using System;
using System.Windows.Forms;
namespace TestNamespace
{
public static class TestClass
{
public static string MessageBox()
{
MessageBox.Show("test");
return "test";
}
}
}
"@ -ReferencedAssemblies System.Windows.Forms
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.