1

我下载了一些包含使用 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
4

2 回答 2

4

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

gmcs -pkg:dotnet *.cs

最新版本的 mono 使用mcs而不是gmcs. 在之前的版本中,mcs目标是 .NET 1.1。

于 2012-06-12T16:47:11.550 回答
2

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

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

专门用于 windows 窗体请参阅:http ://www.mono-project.com/WinForms

希望这可以帮助。

于 2012-06-12T16:51:26.643 回答