【问题标题】:Compiling C# code with Windows Forms in Linux在 Linux 中使用 Windows 窗体编译 C# 代码
【发布时间】:2012-06-12 16:39:17
【问题描述】:

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

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

源代码可以在here下载。如果可能,请描述您将如何编译和运行第 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

【问题讨论】:

  • 是的,这是可能的。工作原理与其余部分相同。 mcs 你就完成了。为什么要问你是否没有尝试过?
  • 嗯,错误似乎很明显:您缺少程序集引用。
  • Mono 不支持 WPF 应用程序。您链接到的 zip 文件也无法打开。
  • @Ramhound 压缩文件没问题。蝉的答案有效。

标签: c# linux mono gmcs


【解决方案1】:

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

gmcs -pkg:dotnet *.cs

最新版本的单声道使用mcs 而不是gmcs。在之前的版本中,mcs 面向 .NET 1.1。

【讨论】:

  • 你没有编译Form1.cs。将 Program.cs 替换为 *.cs 以编译所有 C# 代码,否则只需编写要编译的文件列表。
  • 非常感谢,我才刚刚开始,所以我宁愿先问它是否有意义。
  • @user7236293 如果我使用您提到的方法,Mono 编译器是否可以识别所有需要的文件,例如配置文件、Form1.Designer.cs 等
  • 以防万一:在 CentOS 7 上我遇到了同样的问题。安装包 mono-data-oracle 后,如图所示。
【解决方案2】:

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

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

windows 窗体具体见:http://www.mono-project.com/WinForms

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-11
    • 2015-06-14
    • 2016-10-01
    • 2023-03-22
    • 2020-04-02
    • 1970-01-01
    • 2011-03-04
    • 1970-01-01
    相关资源
    最近更新 更多