我正在尝试在linux中编译一些c#代码,我可以使用Visual Studio命令行中的csc命令在Windows中编译相同的代码。我也已经安装了mono-devel。
这就是准确的错误:
mycode.cs(8,22): error CS0234: The type or namespace name `Forms' does not exist in the namespace `System.Windows'. Are you missing `System.Windows.Forms' assembly reference?
mycode.cs(70,27): error CS0246: The type or namespace name `Form' could not be found. Are you missing an assembly reference?
为什么会发生这种情况,以及如何解决?
这是我用来在linux中编译它的命令:
mcs mycode.cs
在代码中,Windows表单已经包含在内:
using System.Windows.Forms;
同样简单的helloworld代码也可以编译而没有任何错误,我基本上遵循了这篇关于如何在linux中编译c#代码以设置一切的博客文章:
https://jonsson.xyz/2016/11/23/csharp-linux/
您是否尝试过使用-r:System.Windows.Forms.dll
进行编译?
例如:
wc.cs:
using System.Windows.Forms;
public class Program
{
[STAThread]
public static void Main()
{
var f = new Form();
f.Text = "Hello World";
Application.Run(f);
}
}
然后运行:$ mono-csc wf.cs -r:System.Windows.Forms.dll
然后得到wf.exe