在链接期间保留 ICommand

发布于 2025-01-15 12:45:49 字数 489 浏览 5 评论 0原文

在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疾风者 2025-01-22 12:45:55

我不知道为什么 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 each ICommand had the desired effect during Release!

一桥轻雨一伞开 2025-01-22 12:45:55

你组装错了。找出正确程序集的最简单方法是在 Xamarin 项目中按住 CTRL 键并单击符号 ICommand,这将打开一个反编译器窗口,其中该程序集位于 #region 中文件的顶部。

#region Assembly netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
// C:\Program Files\dotnet\sdk\NuGetFallbackFolder\netstandard.library\2.0.3\build\netstandard2.0\ref\netstandard.dll
#endregion

现在将 XML 更改为:

<?xml version="1.0" encoding="utf-8" ?>
<linker>
    <assembly fullname="netstandard">
        <type fullname="System.Windows.Input.ICommand" />
    </assembly>
</linker>

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.

#region Assembly netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
// C:\Program Files\dotnet\sdk\NuGetFallbackFolder\netstandard.library\2.0.3\build\netstandard2.0\ref\netstandard.dll
#endregion

Now change the XML to:

<?xml version="1.0" encoding="utf-8" ?>
<linker>
    <assembly fullname="netstandard">
        <type fullname="System.Windows.Input.ICommand" />
    </assembly>
</linker>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文