我正在尝试使用命令行在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
文件,只需将其放置在与脚本相同的目录下,因为我不知道该怎么做。
请问有人可以解释一下如何使文件编译成功吗?
mcs -reference:System.Drawing.dll Main.cs
,等等。这将在相同目录中查找文件。可能很明显,但你永远不知道。 - atomiculesmcs
在所有平台上都接受/
和-
作为等价选项。 - icktoofay/reference
可以替换为/r
或-r
,以增加简洁性。 - Andrew Tobilko