• Avalonia 部署到麒麟信安操作系统


    1.项目打包

    1.添加一个.desktop文件和快捷方式图标(png)

     .desktop文件内容参考下方:

    1. [Desktop Entry]
    2. Name=AvaloniaApplication1
    3. Type=Application
    4. Exec=/usr/share/AvaloniaApplication1/AvaloniaApplication1
    5. Icon=/usr/share/icons/testapp.png

     2.打开项目文件,添加.desktop和.png

    1. <ItemGroup>
    2. <Content Include="testapp.png" CopyToPublishDirectory="PreserveNewest">
    3. <LinuxPath>/usr/share/icons/testapp.png</LinuxPath>
    4. </Content>
    5. <Content Include="TestCs.desktop" CopyToPublishDirectory="PreserveNewest">
    6. <LinuxPath>/usr/share/applications/TestCs.desktop</LinuxPath>
    7. </Content>
    8. </ItemGroup>

    PS:第1,2步是为了安装完成后能生成一个快捷方式,然而屡次安装成功,从未生成过快捷方式,原因未知。 

    3. 安装 .net打包rpm工具:打开cmd 执行  dotnet tool install --global dotnet-rpm

     4.cd到进入项目文件夹

     依次执行

    1. dotnet restore -r linux-arm64
    2. dotnet rpm install
    3. dotnet msbuild AvaloniaApplication1.csproj /t:CreateRpm /p:TargetFramework=net6.0 /p:RuntimeIdentifier=linux-arm64 /p:Configuration=Release

     4.打包文件路径 E:\project\AvaloniaApplication1\bin\Release\net6.0\linux-arm64,里边会生成一个AvaloniaApplication1.1.0.0.linux-arm64.rpm

    2.项目部署

     1.将发布好的文件夹复制到信安麒麟系统

    2.安装rpm

    rpm –ivh 你打包出来的报名.rpm

     附赠一个删除包指令,以备反复安装,反复报错,反复尝试时使用。

    rpm –e 你打包出来的报名.rpm

    3.由于一直未生成快捷方式,搜索也搜索不到,所以只能到安装目录/usr/share/AvaloniaApplication1/下,执行AvaloniaApplication1,成功了大概就是酱婶儿滴。

     3.运行报错

    1./lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found

    此问题解决参考升级libstdc++.so

    (其中,至少需要1.5小时那部,我大概用了100-110分钟左右)

    2.Default font family name can't be null or empty.巴拉巴拉的

    如果你是11.0以上,建议升级框架至11.0.7以上,框架已经修复该问题!

    如果你是11.0以下:解决方案:

    此时,我滴建议是你先看看你本身有啥字体,然后再去抄百度!!!!!!!

    1.查看系统安装了啥字体

     #fc-list :lang=zh

    2. 然后从你安装的字体里边找一个你心仪的,比如我的字体里有一个KaiTi。

    3.然后新建一个CustomFontManagerImpl.cs 如下:你要修改两处:

    3.1. private readonly Typeface _defaultTypeface =
                new Typeface("resm:AvaloniaApplication1.Assets.Fonts.msyh#微软雅黑");

    这个换成你自己的namespace。

    3.2.    //如果是centos7之类的使用linux里面的字体
                if (skTypeface == null)
                {
                   skTypeface = SKTypeface.FromFamilyName("KaiTi");
                }

    KaiTi换成你刚刚查出来的自己心仪的字体名。

    1. public class CustomFontManagerImpl : IFontManagerImpl
    2. {
    3. private readonly Typeface[] _customTypefaces;
    4. private readonly string _defaultFamilyName;
    5. //Load font resources in the project, you can load multiple font resources
    6. private readonly Typeface _defaultTypeface =
    7. new Typeface("resm:AvaloniaApplication1.Assets.Fonts.msyh#微软雅黑");
    8. public CustomFontManagerImpl()
    9. {
    10. _customTypefaces = new[] { _defaultTypeface };
    11. _defaultFamilyName = _defaultTypeface.FontFamily.FamilyNames.PrimaryFamilyName;
    12. }
    13. public string GetDefaultFontFamilyName()
    14. {
    15. return _defaultFamilyName;
    16. }
    17. public IEnumerable<string> GetInstalledFontFamilyNames(bool checkForUpdates = false)
    18. {
    19. return _customTypefaces.Select(x => x.FontFamily.Name);
    20. }
    21. private readonly string[] _bcp47 = { CultureInfo.CurrentCulture.ThreeLetterISOLanguageName, CultureInfo.CurrentCulture.TwoLetterISOLanguageName };
    22. public bool TryMatchCharacter(int codepoint, FontStyle fontStyle, FontWeight fontWeight, FontFamily fontFamily,
    23. CultureInfo culture, out Typeface typeface)
    24. {
    25. foreach (var customTypeface in _customTypefaces)
    26. {
    27. if (customTypeface.GlyphTypeface.GetGlyph((uint)codepoint) == 0)
    28. {
    29. continue;
    30. }
    31. typeface = new Typeface(customTypeface.FontFamily.Name, fontStyle, fontWeight);
    32. return true;
    33. }
    34. var fallback = SKFontManager.Default.MatchCharacter(fontFamily?.Name, (SKFontStyleWeight)fontWeight,
    35. SKFontStyleWidth.Normal, (SKFontStyleSlant)fontStyle, _bcp47, codepoint);
    36. typeface = new Typeface(fallback?.FamilyName ?? _defaultFamilyName, fontStyle, fontWeight);
    37. return true;
    38. }
    39. public IGlyphTypefaceImpl CreateGlyphTypeface(Typeface typeface)
    40. {
    41. SKTypeface skTypeface;
    42. switch (typeface.FontFamily.Name)
    43. {
    44. case FontFamily.DefaultFontFamilyName:
    45. case "微软雅黑": //font family name
    46. skTypeface = SKTypeface.FromFamilyName(_defaultTypeface.FontFamily.Name); break;
    47. default:
    48. skTypeface = SKTypeface.FromFamilyName(typeface.FontFamily.Name,
    49. (SKFontStyleWeight)typeface.Weight, SKFontStyleWidth.Normal, (SKFontStyleSlant)typeface.Style);
    50. break;
    51. }
    52. // 解决linux系统下skTypeface是null
    53. if (skTypeface == null)
    54. {
    55. skTypeface = SKTypeface.FromFamilyName(_defaultTypeface.FontFamily.Name);
    56. }
    57. //如果是centos7之类的使用linux里面的字体
    58. if (skTypeface == null)
    59. {
    60. skTypeface = SKTypeface.FromFamilyName("KaiTi");
    61. }
    62. return new GlyphTypefaceImpl(skTypeface);
    63. }
    64. }

    然后修改App.axaml.cs

            ///


            /// override RegisterServices register custom service
            ///

            public override void RegisterServices()
            {
                AvaloniaLocator.CurrentMutable.Bind().ToConstant(new CustomFontManagerImpl());
                base.RegisterServices();
            }

    参考资料

    https://www.cnblogs.com/-wxh/p/15976441.html

    https://zhuanlan.zhihu.com/p/498529973

  • 相关阅读:
    【SpringCloud】OpenFeign高级特性
    socks5代理解析:解决在线问题的利器
    NXP i.MX 8M Mini开发板(4核 ARM Cortex-A53)硬件原理图规格说明书
    lv11 嵌入式开发 ARM指令集中(伪操作与混合编程) 7
    【Android】画面卡顿优化列表流畅度三之RecyclerView刷新机制notifyItemRangeInserted
    【算法训练-字符串 三】最长公共子串、最长公共子序列
    HashMap如何确定数组位置
    RFID数字图书馆管理系统
    macOS 12 Monterey 支持电脑型号macOS Monterey 12新功能
    ElasticSearch 实现 全文检索 支持(PDF、TXT、Word、HTML等文件)通过 ingest-attachment 插件实现 文档的检索
  • 原文地址:https://blog.csdn.net/confused_kitten/article/details/127808061