Xamarin.iOS链接器删除反射所需的类中的成员 [英] Xamarin.iOS Linker removes members in class needed for reflection

查看:53
本文介绍了Xamarin.iOS链接器删除反射所需的类中的成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Xamarin项目中,我将链接器行为设置为链接所有引用".这样做时,可通过删除未使用的成员来优化程序集.一个问题,实际上并没有意识到我们需要他们进行反思.我知道有一个Preserve属性,我们可以告诉链接程序将所有符号保留在类中,但是如果程序集是DLL还是不是iOS项目(不引用monotouch程序集,也不能引用),该怎么办? ).有没有一种方法可以将库中的所有类设置为保留",忽略它,或者仅将某些类设置为要优化(反向PreserveAttribute)?

In a Xamarin project, I set the linker behaviour to "Link all references". When doing that, assemblies get optimized by removing unused members. One problem, it's not actually aware that we need them for reflection. I know there is the Preserve attribute that we can put to tell the linker to keep all symbols in the class, but what if the assembly is a DLL or just not an iOS project (doesn't reference the monotouch assemblies, and can't). Is there a way I can set all classes from a library to "preserve", ignore it, or only set certain classes to be optimized (reverse PreserveAttribute) ?

推荐答案

@SharpMobileCode给出了很好的解释,但还有其他两种方法可以解决此问题.

@SharpMobileCode gave a very good explanation but there are also two other ways to solve this.

  1. 使用XML文件,并在项目的选项中的其他mtouch参数下使用--xml=your.file.当您无法更改程序集的源代码时,或者-当您希望/需要使用工具生成要保留的成员列表时,这可能很有用;

  1. Use an XML file and use --xml=your.file in the project's options, under Additional mtouch arguments. That might be useful when you can't change the source code of the assemblies -or- when you want/need to use a tool to generate the list of members to be preserved;

使用新的Preserve(Type)构造函数.这样一来,您就可以在不同程序集中添加保留指令(例如,您的主.exe),该程序集已经引用了Xamarin.iOS.dll(因此无需定义自己的类型).例如

Use the new Preserve(Type) constructor. That allows you to add preserve instructions in a different assembly (e.g. your main .exe) which already has a reference to Xamarin.iOS.dll (so no need to define your own type). E.g.

[assembly: Preserve (typeof (MyType), AllMembers = true)]

这篇关于Xamarin.iOS链接器删除反射所需的类中的成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆