我遇到与 [Mono-dev] monolinker failing on "hello, world"--any ideas? 中描述的问题相同的问题。
C:\monotest>type test.cs
public class Test
{
public static void Main() {
System.Console.WriteLine("BOO");
}
}
C:\monotest>"C:\Program Files (x86)\Mono-2.10.9\bin\monolinker.bat" -a "test.exe" -c link
Fatal error in Mono CIL Linker
System.ArgumentException: Member 'System.Security.AccessControl.AccessRule' is declared in another module and needs to be imported
at Mono.Cecil.MetadataBuilder.LookupToken (IMetadataTokenProvider provider) [0x00000] in <filename unknown>:0
at Mono.Cecil.SignatureWriter.MakeTypeDefOrRefCodedRID (Mono.Cecil.TypeReference type) [0x00000] in <filename unknown>:0
at Mono.Cecil.SignatureWriter.WriteTypeSignature (Mono.Cecil.TypeReference type) [0x00000] in <filename unknown>:0
at Mono.Cecil.SignatureWriter.WriteGenericInstanceSignature (IGenericInstance instance) [0x00000] in <filename unknown>:0
at Mono.Cecil.SignatureWriter.WriteTypeSignature (Mono.Cecil.TypeReference type) [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.GetFieldSignature (Mono.Cecil.FieldReference field) [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.AddField (Mono.Cecil.FieldDefinition field) [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.AddFields (Mono.Cecil.TypeDefinition type) [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.AddType (Mono.Cecil.TypeDefinition type) [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.AddTypeDefs () [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.BuildTypes () [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.BuildModule () [0x00000] in <filename unknown>:0
at Mono.Cecil.MetadataBuilder.BuildMetadata () [0x00000] in <filename unknown>:0
at Mono.Cecil.ModuleWriter.<BuildMetadata>m__18 (Mono.Cecil.MetadataBuilder builder, Mono.Cecil.MetadataReader _) [0x00000] in <filename unknown>:0
at Mono.Cecil.ModuleDefinition.Read[MetadataBuilder,MetadataBuilder] (Mono.Cecil.MetadataBuilder item, System.Func`3 read) [0x00000] in <filename unknown>:0
at Mono.Cecil.ModuleWriter.BuildMetadata (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MetadataBuilder metadata) [0x00000] in <filename unknown>:0
at Mono.Cecil.ModuleWriter.WriteModuleTo (Mono.Cecil.ModuleDefinition module, System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) [0x00000] in <filename unknown>:0
at Mono.Cecil.ModuleDefinition.Write (System.IO.Stream stream, Mono.Cecil.WriterParameters parameters) [0x00000] in <filename unknown>:0
at Mono.Cecil.ModuleDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) [0x00000] in <filename unknown>:0
at Mono.Cecil.AssemblyDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) [0x00000] in <filename unknown>:0
at Mono.Linker.Steps.OutputStep.OutputAssembly (Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <filename unknown>:0
at Mono.Linker.Steps.OutputStep.ProcessAssembly (Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <filename unknown>:0
at Mono.Linker.Steps.BaseStep.Process (Mono.Linker.LinkContext context) [0x00000] in <filename unknown>:0
at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x00000] in <filename unknown>:0
at Mono.Linker.Driver.Run () [0x00000] in <filename unknown>:0
at Mono.Linker.Driver.Main (System.String[] args) [0x00000] in <filename unknown>:0
我没有在Linux下测试过,但引用的例子确实如此。在2.10.8和2.10.9下也是如此。
我找到了一个开源项目,它注释掉了“抛出CreateForeignMemberException(member);”的调用。在塞西尔,这是造成这种情况的原因: Simple Assembly Explorer, svn/trunk/Mono.Cecil/Mono.Cecil/AssemblyWriter.cs 。
GitHub上Cecil的主干仍然激活了该代码。我厌倦了首先删除一条我不理解的支票。
在Stack Overflow问题 Is there a free tool capable of pruning unused code from a CLI assembly? 中,Mono链接器的作者建议自己编译:
请注意,所有已发布的Mono版本都附带了链接器的编译版本,但我建议您自己编译。
为什么我需要自己编译?我该怎么做才能让这个工作?我现在真的只是在探索这个用途,但它看起来很有希望。