如何使用Add-Type在System.Windows.Forms命名空间中添加C#代码?(How can I Use Add-Type to add C# code with System.Windows.Forms namespace?)
如何使用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#代码。 请不要给我替代。
How can I use Add-Type to add C# code with System.Windows.Forms namespace? 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?)
I just want to use ONLY C# code in PowerShell. Please don't give me alternative.
最满意答案
使用ReferencedAssemblies参数添加对包含程序集( System.Windows.Forms.dll文件)的ReferencedAssemblies :
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.FormsAdd a reference to the containing assembly (the System.Windows.Forms.dll file), using the ReferencedAssemblies parameter:
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更多推荐
发布评论