在Visual Studio 2010中使用GTK#

13

我一整天都在尝试让GTK#在Windows Server 2008 R2 x64的Visual Studio 2010上工作,以便我可以开始编写漂亮的跨平台GUI应用程序,但我对C#还比较陌生,遇到了很多麻烦。

我安装了包含GTK#的最新的Mono for Windows。我还安装了一个Mono 2.10.8配置文件,将其作为我的项目目标框架,大致按照这里的指南:http://erictummers.wordpress.com/2012/01/25/target-mono-from-visual-studio/

我创建了一个新的Windows Forms应用程序,并删除了对Windows Forms的引用,添加了对GTK#的引用,大致按照这里的指南:http://jrwren.wrenfam.com/blog/2008/11/01/gtk-in-visual-studio-2008-on-vista-x64/

我还添加了对gtk-dotnet的引用,除了那个指南中的引用。

这是我的应用程序的完整代码:
using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using Gtk;

namespace GridToGo
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.Init();
            Window myWin = new Window("My first GTK# Application! ");
            myWin.Resize(200, 200);
            myWin.Destroyed += new EventHandler(myWin_Destroyed);
            Label myLabel = new Label();
            myLabel.Text = "Hello World!!!!";
            myWin.Add(myLabel);
            myWin.ShowAll();
            Application.Run();
        }

        static void myWin_Destroyed(object sender, EventArgs e)
        {
            Application.Quit();
        }
    }
}

无论我使用哪种配置尝试运行此程序,都会出现以下异常:
System.TypeInitializationException was unhandled
  Message=The type initializer for 'Gtk.Application' threw an exception.
  Source=gtk-sharp
  TypeName=Gtk.Application
  StackTrace:
       at Gtk.Application.Init()
       at GridToGo.Program.Main() in F:\visual-studio\GridToGo\GridToGo\Program.cs:line 13
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.DllNotFoundException
       Message=Unable to load DLL 'glibsharpglue-2': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
       Source=glib-sharp
       TypeName=""
       StackTrace:
            at GLib.Thread.glibsharp_g_thread_supported()
            at GLib.Thread.get_Supported()
            at Gtk.Application..cctor()
       InnerException: 

我无法弄清楚如何让它找到那个dll文件!我甚至尝试将4个DLL文件复制到解决方案中几乎每个文件夹中,使用以下名称:glibsharpglue-2 glibsharpglue-2.dll glibsharpglue-2.o glibsharpglue-2.o.dll!我甚至尝试安装GTK全套包并将其bin文件夹添加到系统路径中,然后将相同的4个dll文件复制到该文件夹中,但都没有成功。

对于我的疯狂问题有什么建议吗?我感觉我在这里漏掉了什么重要的东西。 >_<

1个回答

20

我弄清楚了!Windows上的Mono是完全不必要的。.NET的GTK#才是我需要的。对于未来想要为跨平台GTK#开发设置他们的Windows环境的任何人,以下是我遵循的步骤:

  1. 根据此处的说明安装一个面向Mono项目的目标:http://erictummers.wordpress.com/2012/01/25/target-mono-from-visual-studio/
  2. 从官方Mono下载站点安装.NET的GTK#。
  3. 在Windows上安装Glade / GTK+,源forge项目位于此处:http://sourceforge.net/projects/gladewin32/
  4. 创建一个面向Mono的新C#项目。
  5. 从你安装GTK#for .NET的位置引用你项目所需的必要程序集。

感谢您回来并解释! - heltonbiker
我很好奇,你为什么想要针对Mono进行开发?使用微软的Visual C#编译器存在什么问题吗?如果兼容性足够好,我认为Mono或者Microsoft的编译器都能生成二进制文件,并在Mono或Microsoft的.NET运行时上运行。 - David Grayson
说实话,当时我感到非常绝望和困惑,于是我发布了第一组对我有用的步骤。针对Mono可能并不重要,我无从得知,因为我找到这个方法的项目早已被放弃了。哈哈 - HOLOGRAPHICpizza

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接