简体   繁体   English

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

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

I downloaded a few source codes containing C# code that uses windows forms. 我下载了一些包含使用Windows窗体的C#代码的源代码。 Is it possible to compile the codes under the Linux environment (Ubuntu 12.04) and run it? 是否可以在Linux环境(Ubuntu 12.04)下编译代码并运行它?

I already tried successfully to compile a few C# source codes with mcs and run the resulting exe file with mono . 我已经尝试使用mcs成功编译一些C#源代码,并使用mono运行生成的exe文件。

The source codes can be downloaded here . 可以在此处下载源代码。 If it's possible please describe how would you compile and run chapter 2/OpeningDocument solution. 如果可能,请描述如何编译和运行第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

EDIT 编辑

$ 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

If you're not using the latest version of Mono, this should work: 如果您没有使用最新版本的Mono,则应该可以使用:

gmcs -pkg:dotnet *.cs

The latest version of mono uses mcs instead of gmcs . mono的最新版本使用mcs代替gmcs In the previous ones, mcs targets .NET 1.1. 在以前的版本中, mcs面向.NET 1.1。

You may wish to run your code against the mono migration analyser to see what fails or isn't supported. 您可能希望针对Mono迁移分析器运行代码,以查看失败或不支持的内容。 You can find the tool here: http://www.mono-project.com/MoMA . 您可以在这里找到该工具: http : //www.mono-project.com/MoMA NOTE For the tool to work you will need access to a windows machine. 注意要使该工具正常工作,您需要访问Windows计算机。

You can also take a look at current mono compatibility with various .Net features at http://www.mono-project.com/Compatibility . 您还可以在http://www.mono-project.com/Compatibility上查看当前与各种.Net功能的单声道兼容性。

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

Hope this helps. 希望这可以帮助。

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

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