问题
I'm trying to compile a C# script with Mono on Debian by command line, like this:
gmcs Main.cs
However, I get the following error:
Main.cs(6,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing an assembly reference?
Main.cs(7,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing an assembly reference?
Main.cs(12,7): error CS0246: The type or namespace name `iTextSharp' could not be found. Are you missing a using directive or an assembly reference?
Main.cs(13,7): error CS0246: The type or namespace name `iTextSharp' could not be found. Are you missing a using directive or an assembly reference?
Main.cs(1526,31): error CS0246: The type or namespace name `Bitmap' could not be found. Are you missing a using directive or an assembly reference?
Main.cs(6,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing an assembly reference?
Main.cs(7,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing an assembly reference?
Main.cs(12,7): error CS0246: The type or namespace name `iTextSharp' could not be found. Are you missing a using directive or an assembly reference?
Main.cs(13,7): error CS0246: The type or namespace name `iTextSharp' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 9 error(s), 1 warnings
These the references at the top of Main.cs:
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using iTextSharp.text;
using iTextSharp.text.pdf;
I understand that I have to tell Mono which libraries to include by adding -pkg:whatever. My problem is that I do not know what these libraries are called, so I don't know what command is used to include them. Actually, I don't even know whether I have to download these libraries from somewhere or whether they come with Mono.
Note also that the last 2 are the iTextSharp library, for which I have itextsharp.dll just placed in the same directory as the script, since I don't know what else to do with it.
Please could someone explain to me how to get the file to compile!
回答1:
Try this:
gmcs /reference:System.Drawing.dll /reference:itextsharp.dll Main.cs
With newer versions of mono, try this.
mcs /reference:System.Drawing.dll /reference:itextsharp.dll Main.cs
回答2:
Here's another solution that's worked for me in a similar case where I got this error:
Eventdemo.cs(2,14): error CS0234: The type or namespace name `Drawing' does not exist in the namespace `System'. Are you missing `System.Drawing' assembly reference?
Eventdemo.cs(3,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference? │
Eventdemo.cs(8,19): error CS0246: The type or namespace name `Form' could not be found. Are you missing an assembly reference?
I had those references in my program:
using System;
using System.Drawing;
using System.Windows.Forms;
I got the solution from ubuntuforums:
gmcs -pkg:dotnet *.cs
回答3:
I got this error, and when I just needed to use System.Net.Http, I used:
$mcs /reference:System.Net.Http.dll Program.cs
and it worked fine for me. When I tried to include the full path to System.Net.Http.dll, it didn't work. That is to say, heads up, mono keeps track of paths. Also, I have the latest version of mono.
来源:https://stackoverflow.com/questions/8264783/how-to-reference-these-packages-with-mono-in-order-to-compile