繁体   English   中英

在Linux中使用Windows窗体编译C#代码

[英]Compiling C# code with Windows Forms in Linux

我下载了一些包含使用Windows窗体的C#代码的源代码。 是否可以在Linux环境(Ubuntu 12.04)下编译代码并运行它?

我已经尝试使用mcs成功编译一些C#源代码,并使用mono运行生成的exe文件。

可以在此处下载源代码。 如果可能,请描述如何编译和运行第2章/ OpeningDocument解决方案。

$ mcs Program.cs 
Program.cs(3,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
Compilation failed: 1 error(s), 0 warnings

编辑

$ gmcs -pkg:dotnet Program.cs 
Program.cs(17,33): error CS0246: The type or namespace name `Form1' could not be found. Are you missing a using directive or an assembly reference?
Program.cs(17,25): error CS1502: The best overloaded method match for `System.Windows.Forms.Application.Run(System.Windows.Forms.Form)' has some invalid arguments
/usr/lib/mono/gac/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll (Location of the symbol related to previous error)
Program.cs(17,25): error CS1503: Argument `#1' cannot convert `object' expression to type `System.Windows.Forms.Form'
Compilation failed: 3 error(s), 0 warnings

如果您没有使用最新版本的Mono,则应该可以使用:

gmcs -pkg:dotnet *.cs

mono的最新版本使用mcs代替gmcs 在以前的版本中, mcs面向.NET 1.1。

您可能希望针对Mono迁移分析器运行代码,以查看失败或不支持的内容。 您可以在这里找到该工具: http : //www.mono-project.com/MoMA 注意要使该工具正常工作,您需要访问Windows计算机。

您还可以在http://www.mono-project.com/Compatibility上查看当前与各种.Net功能的单声道兼容性。

专门针对Windows窗体,请参见: http : //www.mono-project.com/WinForms

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM