gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:24:46 24 4
gpt4 key购买 nike

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

最佳答案

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

gmcs -pkg:dotnet *.cs

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

关于c# - 在 Linux 中使用 Windows 窗体编译 C# 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11000971/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com