【问题标题】:The type or namespace name 'Cecil' does not exist in the namespace 'Mono'命名空间“Mono”中不存在类型或命名空间名称“Cecil”
【发布时间】:2013-07-22 16:03:51
【问题描述】:

我是 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/ 中

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

问候

普利燕

【问题讨论】:

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

标签: c# linux mono mono.cecil


【解决方案1】:

您需要使用-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_4_0_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 是核心包的一部分还是不是)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    • 2018-05-09
    • 2022-01-11
    • 2021-10-15
    相关资源
    最近更新 更多