如何在Mono中引用这些软件包以进行编译

36

我正在尝试使用命令行在Debian上通过Mono编译一个C#脚本,像这样:

gmcs Main.cs

但是,我遇到了以下错误:

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

这些是在 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;

我知道我必须通过添加 -pkg:whatever 来告诉 Mono 要包含哪些库。我的问题是,我不知道这些库叫什么名字,所以我也不知道用什么命令来包含它们。事实上,我甚至不知道这些库是不是要从某个地方下载或者它们是否随 Mono 一起安装。

同时请注意,最后两个库是 iTextSharp 库,我有一个 itextsharp.dll 文件,只需将其放置在与脚本相同的目录下,因为我不知道该怎么做。

请问有人可以解释一下如何使文件编译成功吗?

3个回答

57

试试这个:

gmcs /reference:System.Drawing.dll /reference:itextsharp.dll Main.cs

对于较新的 Mono 版本,请尝试使用这个方法。

mcs /reference:System.Drawing.dll /reference:itextsharp.dll Main.cs

好的,没问题。谢谢!等网站允许时我会接受你的答案。 - Alasdair
3
有了新的Mono版本,现在只有一个编译器,那就是mcs。 - Salil
1
在OSX上,它将是mcs -reference:System.Drawing.dll Main.cs,等等。这将在相同目录中查找文件。可能很明显,但你永远不知道。 - atomicules
1
@atomicules:mcs 在所有平台上都接受 /- 作为等价选项。 - icktoofay
/reference 可以替换为 /r-r,以增加简洁性。 - Andrew Tobilko

7

这是我在类似情况下遇到此错误时使用的另一种解决方法:

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?  

我在我的程序中有这些引用:

using System;
using System.Drawing;
using System.Windows.Forms; 

我从ubuntuforums上找到了解决方案:

 gmcs -pkg:dotnet *.cs

0

我遇到了这个错误,当我只需要使用System.Net.Http时,我使用了:

$mcs /reference:System.Net.Http.dll Program.cs

对我来说,它运行得很好。当我尝试包含完整路径到System.Net.Http.dll时,它没有起作用。也就是说,注意了,Mono会跟踪路径。此外,我有最新版本的Mono。


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