使用C#、. NET Core 3和GTK#进行跨平台编程(和替代方法)

问题描述 投票:1回答:1

如果可能,我将开始开发应在Linux和Windows上运行的软件项目。因为我已经对C#有一定的经验,所以我很想在此项目中使用它。我以为.NET Core 3和GTK#3.22应该不会有问题,因为.NET Core App应该是跨平台的。根据我的理解,GTK#应该可以在任何地方使用相同版本的GTK +。

为什么要使用C#?好吧,我喜欢这种语言,并且有一个我想使用的用于c#的ECS框架。

到目前为止,我已经在Visual Studio中设置了针对.NET Core 3的测试控制台应用程序项目,并添加了GTK# specific NuGet package

我编写了一个简单的Hello World程序来测试环境。

using System;
using Gtk;

namespace GTKTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Application.Init();
            Window win = new Window("Hello GTK");
            Label lbl = new Label("This is a test GTK App written with C# for GNU/Linux and Windows");
            win.DeleteEvent += Win_DeleteEvent;
            win.Add(lbl);
            win.ShowAll();
            Application.Run();
            win.Dispose();
            Console.Write("Press any key...");
            Console.ReadKey();
        }

        private static void Win_DeleteEvent(object o, DeleteEventArgs args)
        {
            Application.Quit();
            args.RetVal = true;
        }

    }
}

[当我从Visual Studio 2019运行此代码时,我得到了

System.TypeInitializationException
  HResult=0x80131534
  Message=The type initializer for 'Gtk.Application' threw an exception.
  Source=GtkSharp
  StackTrace:
   at Gtk.Application.Init()
   at GTKTest.Program.Main(String[] args) in D:\Workspace\VSRepos\C#\GTKTest\Program.cs:line 10

Inner Exception 1:
DllNotFoundException: Gtk

寻找解决方案时,我安装了mono和GTK# for Windows from this page。如果我坚持使用.NET Core,则单声道部分不必要。

我想念的是什么?我究竟做错了什么?我正在尝试实现的目标像我正在想象的那样吗?我也对如何使用C#编程跨平台GUI软件感兴趣。我偶然发现了electron.js,但听说它有一些巨大的内存开销,而且我不太喜欢javascript。 AvaloniaUI听起来很有趣,但我认为上述方法会更好。

编辑:在添加了建议的here in step 3的msys路径后,从上面的异常开始出现以下错误。错误指出在dll中找不到过程入口点。

enter image description here

c# .net-core mono cross-platform gtk#
1个回答
0
投票

https://github.com/GtkSharp/GtkSharp您可以从那里开始阅读整个存储库吗?>

© www.soinside.com 2019 - 2024. All rights reserved.