在链接期间保留 ICommand
在我的 Xamarin.Forms 代码中,我多次使用 ICommand
来创建超链接。
代码在调试期间工作正常,但该命令在链接器发布期间被删除。
我在 Android 项目的根目录中创建了一个 XML 文件,其 Build Action
设置为 LinkDescription
,其中包含以下代码:
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<assembly fullname="System">
<type fullname="System.Windows.Input.ICommand"></type>
</assembly>
</linker>
我希望这会保留该命令,但没有;发布期间链接再次失效。我做错了什么吗?
In my Xamarin.Forms code I use ICommand
several times for creating hyperlinks.
The code works fine during debugging, but the command gets removed during release by the linker.
I created an XML file in the root of my Android project with its Build Action
set to LinkDescription
, that has the following code:
<?xml version="1.0" encoding="utf-8" ?>
<linker>
<assembly fullname="System">
<type fullname="System.Windows.Input.ICommand"></type>
</assembly>
</linker>
I expected that would preserve the command, but no; the links again don't work during release. Am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道为什么 XML 解决方案不起作用,但以下是在我的情况下有效的方法:
在每个
ICommand
之前使用[Preserve]
属性在释放!I don't know why the XML solution did not work, but here is what worked in my case:
Using the
[Preserve]
attribute before eachICommand
had the desired effect during Release!你组装错了。找出正确程序集的最简单方法是在 Xamarin 项目中按住 CTRL 键并单击符号
ICommand
,这将打开一个反编译器窗口,其中该程序集位于#region
中文件的顶部。现在将 XML 更改为:
You've got the wrong assembly. The easiest way to figure out the right assembly is to CTRL + Click the symbol
ICommand
in a Xamarin project, which will open a decompiler window with the assembly in a#region
at the top of the file.Now change the XML to: