C# 类型或命名空间名称';塞西尔';命名空间中不存在';单声道';

C# 类型或命名空间名称';塞西尔';命名空间中不存在';单声道';,c#,linux,mono,mono.cecil,C#,Linux,Mono,Mono.cecil,我不熟悉C#编程。 我正在尝试编译一个需要mono cecil的C#程序 这就是我试图编译的代码 我不知道如何添加参考…有人能帮我吗 using System; using Mono.Cecil; using Mono; public class Program { public static void Main() { string infile = "in.exe"; string outfile = "out.exe"; Guid guid = Guid.Pa

我不熟悉C#编程。 我正在尝试编译一个需要mono cecil的C#程序

这就是我试图编译的代码 我不知道如何添加参考…有人能帮我吗

using System;
using Mono.Cecil;
using Mono;

public class Program {
  public static void Main() {
    string infile = "in.exe";
    string outfile = "out.exe";
    Guid guid = Guid.Parse("12345678-1234-1234-1234-1234567890ab");
    AssemblyDefinition asm = AssemblyDefinition.ReadAssembly(infile);
    ModuleDefinition mod = asm.MainModule;
    mod.Mvid = guid;
    asm.Write(outfile);
  }
}
当我使用mcs编译程序时,我得到以下错误

error CS0234: The type or namespace name 'Cecil' does not exist in the namespace 'Mono'.Are you missing an assembly reference?
我在/usr/lib/Mono/4.0和/usr/lib/Mono/2.0中找不到Mono.Cecil.dll。 Mono.Cecil.dll仅存在于/usr/lib/monodevelop/bin中/

如果我遗漏了什么,请告诉我?我该如何摆脱这个错误

问候


Puliyan

您需要使用
-r
-pkg
-lib
选项告诉编译器在哪里可以找到
Mono.Cecil.dll

始终有效的解决方案是从源代码构建
.dll

git clone https://github.com/mono/cecil.git
cd cecil
xbuild /property:Configuration=net_4_0_Release
您还可以使用其他配置(例如,
net\u 4\u 0\u Debug
)。检查
.sln
.csproj
文件中的值。您将在
obj
子目录中找到
Mono.Cecil.dll
。然后,您可以将该库复制到您想要的任何位置,并使用
-r:/path/to/Mono.Cecil.dll
-lib:/path/to/libdirectory-r:Mono.Cecil.dll
,或者如果您使用的是MonoDevelop,则添加对库的引用(在MonoDevelop中,您还应该能够直接引用项目)

Cecil通常也应通过
pkg config
机制提供;但是,
cecil.pc
文件似乎配置错误。通常情况下,仅使用
-pkg:cecil
就足够了,但这似乎是不正确的,您必须使用以下内容:

dmcs -r:`pkg-config --variable=Libraries`
以获取GAC中Mono.Cecil.dll的完整路径


此外,由于mono在Debian下分为多个软件包,如果上述功能不起作用,您可能需要安装额外的库(我目前不知道Cecil是否是核心软件包的一部分)。

您需要告诉编译器
-r
-pkg
,或者
-lib
选项,从中可以找到
Mono.Cecil.dll

始终有效的解决方案是从源代码构建
.dll

git clone https://github.com/mono/cecil.git
cd cecil
xbuild /property:Configuration=net_4_0_Release
您还可以使用其他配置(例如,
net\u 4\u 0\u Debug
)。检查
.sln
.csproj
文件中的值。您将在
obj
子目录中找到
Mono.Cecil.dll
。然后,您可以将该库复制到您想要的任何位置,并使用
-r:/path/to/Mono.Cecil.dll
-lib:/path/to/libdirectory-r:Mono.Cecil.dll
,或者如果您使用的是MonoDevelop,则添加对库的引用(在MonoDevelop中,您还应该能够直接引用项目)

Cecil通常也应通过
pkg config
机制提供;但是,
cecil.pc
文件似乎配置错误。通常情况下,仅使用
-pkg:cecil
就足够了,但这似乎是不正确的,您必须使用以下内容:

dmcs -r:`pkg-config --variable=Libraries`
以获取GAC中Mono.Cecil.dll的完整路径


此外,由于mono在Debian下分为多个软件包,如果上述功能不起作用,您可能需要安装其他库(我目前不知道Cecil是否是核心软件包的一部分)。

无论其位置如何,您都必须将对该DLL的引用添加到您的项目中。你这样做了吗?仅使用是不够的。嘿,唐,我现在已经把我的问题说清楚了,很抱歉不同意:)无论它位于何处,您都必须将对该DLL的引用添加到您的项目中。你这样做了吗?仅使用是不够的。嘿,唐,我现在已经把我的问题说清楚了,很抱歉我的疏忽:)