我一整天都在尝试让 GTK# 在 Windows Server 2008 R2 x64 上的 Visual Studio 2010 中工作,这样我就可以开始编写不错的跨平台 GUI 应用程序,但我对 C# 有点陌生,而且我有麻烦的世界。
我为 Windows 安装了最新的 Mono,其中包括 GTK#。我还按照此处的指南安装了一个 Mono 2.10.8 配置文件作为我项目的目标框架:http://erictummers.wordpress.com/2012/01/25/target-mono-from-visual-studio/
我创建了一个新的 Windows 窗体应用程序并删除了对 Windows 窗体内容的引用并添加了对 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 站点安装 GTK 一体化软件包并将其 bin 文件夹添加到我的系统路径,然后将相同的 4 个 dll 复制到该文件夹,但都没有成功。
对我的疯狂问题有什么建议吗?我觉得我在这里错过了一些大事。 >_<
最佳答案
我想通了! Windows 的 Mono 是完全没有必要的。 .NET 的 GTK# 正是我所需要的。对于将来想要为跨平台 GTK# 开发设置 Windows 环境的任何人,以下是我遵循的步骤:
- 按照此处的说明安装 Mono 项目目标:http://erictummers.wordpress.com/2012/01/25/target-mono-from-visual-studio/
- 从官方 Mono 下载站点安装适用于 .NET 的 GTK#。
- 在此处安装适用于 Windows 的 Glade/GTK+,sourceforge 项目:http://sourceforge.net/projects/gladewin32/
- 创建一个针对 Mono 的新 C# 项目。
- 从安装 GTK# for .NET 的地方引用项目所需的程序集。
关于c# - Visual Studio 2010 中的 GTK#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11337333/