Error CS0246 when trying to use Gtk#

2019-08-14 14:46发布

问题:

I am trying to build a project using Gtk#.

I have used Gtk# before, and I have always been using SharpDevelop for doing so.

Just that now ... it doesn't seem to work any more:

  • I have installed the latest release, Gtk# 2.12.26 for .NET, with the installer package from the Mono website, as I have formerly done with earlier versions.
  • I have created a C# command line application project in SharpDevelop, using C# 3.0 and targetting .NET 3.5.
  • I have added GAC references from my project to atk-sharp, gdk-sharp, glib-sharp, gtk-sharp, Mono.Cairo, and pango-sharp.
  • I have added using Gtk; into my main C# file.
  • When I write Gtk., SharpDevelop's IntelliSense will show all the types found in the Gtk namespace.
  • When I compile the project, the compiler aborts with the following message:

The type or namespace name 'Gtk' could not be found (are you missing a using directive or an assembly reference?) (CS0246)

What am I missing?

This happens only when I target .NET 3.5. When I target .NET 4.0, I run into a different problem.

The complete output of the compiler (slightly anonymized) reads as follows:

Build started.
Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Mono.Cairo". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
Warning MSB3245: Could not resolve this reference. Could not locate the assembly "pango-sharp". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
Warning MSB3245: Could not resolve this reference. Could not locate the assembly "gtk-sharp". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
Warning MSB3245: Could not resolve this reference. Could not locate the assembly "gdk-sharp". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
Warning MSB3245: Could not resolve this reference. Could not locate the assembly "glib-sharp". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
Warning MSB3245: Could not resolve this reference. Could not locate the assembly "atk-sharp". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
Compiling ...
...\Program.cs(3,7) : Error CS0246: The type or namespace name 'Gtk' could not be found (are you missing a using directive or an assembly reference?)
Build failed. (00:00:00.1930110)