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

1.项目打包

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

 .desktop文件内容参考下方:

[Desktop Entry]
Name=AvaloniaApplication1
Type=Application
Exec=/usr/share/AvaloniaApplication1/AvaloniaApplication1
Icon=/usr/share/icons/testapp.png

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

	<ItemGroup>
		<Content Include="testapp.png" CopyToPublishDirectory="PreserveNewest">
			<LinuxPath>/usr/share/icons/testapp.png</LinuxPath>
		</Content>
		<Content Include="TestCs.desktop" CopyToPublishDirectory="PreserveNewest">
			<LinuxPath>/usr/share/applications/TestCs.desktop</LinuxPath>
		</Content>
	</ItemGroup>

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

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

 4.cd到进入项目文件夹

 依次执行

dotnet restore -r linux-arm64
dotnet rpm install
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换成你刚刚查出来的自己心仪的字体名。

 public class CustomFontManagerImpl : IFontManagerImpl
    {
        private readonly Typeface[] _customTypefaces;
        private readonly string _defaultFamilyName;

        //Load font resources in the project, you can load multiple font resources
        private readonly Typeface _defaultTypeface =
            new Typeface("resm:AvaloniaApplication1.Assets.Fonts.msyh#微软雅黑");

        public CustomFontManagerImpl()
        {
            _customTypefaces = new[] { _defaultTypeface };
            _defaultFamilyName = _defaultTypeface.FontFamily.FamilyNames.PrimaryFamilyName;
        }

        public string GetDefaultFontFamilyName()
        {
            return _defaultFamilyName;
        }

        public IEnumerable<string> GetInstalledFontFamilyNames(bool checkForUpdates = false)
        {
            return _customTypefaces.Select(x => x.FontFamily.Name);
        }

        private readonly string[] _bcp47 = { CultureInfo.CurrentCulture.ThreeLetterISOLanguageName, CultureInfo.CurrentCulture.TwoLetterISOLanguageName };

        public bool TryMatchCharacter(int codepoint, FontStyle fontStyle, FontWeight fontWeight, FontFamily fontFamily,
            CultureInfo culture, out Typeface typeface)
        {
            foreach (var customTypeface in _customTypefaces)
            {
                if (customTypeface.GlyphTypeface.GetGlyph((uint)codepoint) == 0)
                {
                    continue;
                }

                typeface = new Typeface(customTypeface.FontFamily.Name, fontStyle, fontWeight);

                return true;
            }

            var fallback = SKFontManager.Default.MatchCharacter(fontFamily?.Name, (SKFontStyleWeight)fontWeight,
                SKFontStyleWidth.Normal, (SKFontStyleSlant)fontStyle, _bcp47, codepoint);

            typeface = new Typeface(fallback?.FamilyName ?? _defaultFamilyName, fontStyle, fontWeight);

            return true;
        }

        public IGlyphTypefaceImpl CreateGlyphTypeface(Typeface typeface)
        {
            SKTypeface skTypeface;

            switch (typeface.FontFamily.Name)
            {
                case FontFamily.DefaultFontFamilyName:
                case "微软雅黑":  //font family name
                    skTypeface = SKTypeface.FromFamilyName(_defaultTypeface.FontFamily.Name); break;
                default:
                    skTypeface = SKTypeface.FromFamilyName(typeface.FontFamily.Name,
                        (SKFontStyleWeight)typeface.Weight, SKFontStyleWidth.Normal, (SKFontStyleSlant)typeface.Style);
                    break;
            }

            // 解决linux系统下skTypeface是null
            if (skTypeface == null)
            {
                skTypeface = SKTypeface.FromFamilyName(_defaultTypeface.FontFamily.Name);
            }

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

            return new GlyphTypefaceImpl(skTypeface);
        }
    }

然后修改App.axaml.cs

        /// <summary>
        /// override RegisterServices register custom service
        /// </summary>
        public override void RegisterServices()
        {
            AvaloniaLocator.CurrentMutable.Bind<IFontManagerImpl>().ToConstant(new CustomFontManagerImpl());
            base.RegisterServices();
        }

参考资料

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值