用户体验设计专业,广东网站seo,西安植提行业网站建设,网站建设的技术体会2023年11月15日#xff0c;对.net的开发圈是一个重大的日子#xff0c;.net 8.0正式版发布。
圈内已经预热了有半个月有余#xff0c;性能不断超越#xff0c;开发体验越来越完美#xff0c;早在.net 5.0的时候就各种吹风Aot编译#xff0c;直到6.0 7.0使用仍然比较麻烦…2023年11月15日对.net的开发圈是一个重大的日子.net 8.0正式版发布。
圈内已经预热了有半个月有余性能不断超越开发体验越来越完美早在.net 5.0的时候就各种吹风Aot编译直到6.0 7.0使用仍然比较麻烦我个人比较期待本次更新的aot体验。
有的群友几个小时都等不了啦半夜就开始更新预览版我是等到第二天早上正式布发布才开始的开机第一件事情下载.net8.0 SDK随后更新vs2022企业版。 支持开源
我是开源人https://github.com/2881099
本文通过我们的开源项目升级以及AOT试验记录了整个经验过程。
使用我们开源项目的朋友一般都知道特点依赖较少甚至零依赖每次 .net 新版本发布很轻松就支持了并且为 AOT 埋下了种子。
第一个要更新的开源项目是FreeRedis这个项目没有任何外部依赖本身是支持.net 8.0的本次维护主要把和测试有关项目类型修改成.net8.0前后只花了大概十分钟跑完测试后发布了 FreeRedis 1.2.5 FreeRedis 是 .NETFramework 4.0 及以上 访问 redis-server 的客户端组件 第二个要更新的开源项目是CSRedisCore大致步骤同上目前这个项目处于稳定维护阶段不再增加新功能。 CSRedisCore 是 .NETFramework 4.0 及以上 访问 redis-server 的客户端组件也是 FreeSql 作者早年发布的 nuget 版本 第三个要更新的开源项目是FreeSql这个项目比较庞大解决方案内有50个子项目由于主项目也是零依赖所以基本不需要修改就支持.net8.0。最新编译器提示.netcoreapp2.1高风险漏洞的警告不得已移除了.netcoreapp2.1有关的依赖注入支持前后大约花了半个小时测试后发布了 FreeSql 3.2.805 FreeSql 是一款功能强大的对象关系映射O/RM组件支持 .NET Core 2.1、.NET Framework 4.0 以及 Xamarin✨ 第四个要更新的项目是FreeScheduler这是一个纯净版的定时任务框架依赖较少只花了5分钟测试发布。 FreeScheduler 实现轻量化定时任务调度支持集群、临时的延时任务和重复循环任务(可持久化)可按秒每天/每周/每月固定时间自定义间隔执行支持 .NET Core 2.1、.NET Framework 4.0 运行环境。 其他几个开源项目稳定且不依赖 .net 版本所以本次无需维护更新。 测试与支持 FreeRedis aot
下午没事去买了一杯咖啡到12点钟还睡不着刷视频刷到一点半还是睡不着于是想折腾点什么东西正好.net 8.0 aot特性测试一下FreeRedis看看是否支持。
我是直接创建控制台程序测试的设置成aot发布之后.csproj 内容如下
Project SdkMicrosoft.NET.SdkPropertyGroupOutputTypeExe/OutputTypeTargetFrameworknet8.0/TargetFrameworkPublishAotTrue/PublishAot/PropertyGroupItemGroupPackageReference IncludeFreeRedis Version1.2.5 //ItemGroup
/Project发布 aot 需要使用控制台命令 dotnet publish -r win-x64 -c release 第一次发布失败提示要安装桌面版C于是我重新去官网下载vS2022企业版安装器运行它点击修改安装选中桌面版C进行安装大概过了15分钟安装完毕。 E:\github\FreeRedis\examples\console_net8dotnet publish -r win-x64 -c release
适用于 .NET MSBuild 版本 17.8.3195e7f5a3正在确定要还原的项目…所有项目均是最新的无法还原。console_net8 - E:\github\FreeRedis\examples\console_net8\bin\release\net8.0\win-x64\console_net8.dllGenerating native code
C:\Users\28810\.nuget\packages\freeredis\1.2.5\lib\netstandard2.0\FreeRedis.dll : warning IL3053: Assembly FreeRedis
produced AOT analysis warnings. [E:\github\FreeRedis\examples\console_net8\console_net8.csproj]
C:\Users\28810\.nuget\packages\freeredis\1.2.5\lib\netstandard2.0\FreeRedis.dll : warning IL2104: Assembly FreeRedis
produced trim warnings. For more information see https://aka.ms/dotnet-illink/libraries [E:\github\FreeRedis\examples\c
onsole_net8\console_net8.csproj]console_net8 - E:\github\FreeRedis\examples\console_net8\bin\release\net8.0\win-x64\publish\只要编译成功发布aot必然会成功只是会有一些警告。 2023/11/16 13:06 5,637,120 console_net8.exe
2023/11/16 13:06 137,695,232 console_net8.pdb
2023/11/16 04:13 127,268 FreeRedis.pdb请无视 .pdb 文件它是调试用途的可以删除console_net8.exe 只有 5兆大小。
第二次发布后运行成功了纯字符串数值之内的操作全部成功。
正当得意之时redis.AclGetUser 方法抛出了一个新的错误该方法返回的是一个实体类型 AclGetUserResult有使用 Activetor.CreateInstance(typeof(AclGetUserResult))Aot本身是支持这个方法的错误提示是不支持该方法的对象类型 AclUserResult。
Unhandled Exception: System.MissingMethodException: No parameterless constructor defined for type FreeRedis.AclGetUserResult.at System.ActivatorImplementation.CreateInstance(Type, Boolean) 0x119at FreeRedis.RespHelper.CreateInstanceGetDefaultValue(Type) 0x120at FreeRedis.RespHelper.MapToClass[T](Object[], Encoding) 0x4aat FreeRedis.RedisClient.c__DisplayClass457_0.AclGetUserb__1(Object[] a, Boolean _) 0x220at FreeRedis.RedisResult.ThrowOrValue[TValue](Func3) 0x58at FreeRedis.RedisClient.PoolingAdapter.c__DisplayClass9_01.AdapterCallb__0() 0x141at FreeRedis.RedisClient.LogCallCtrl[T](CommandPacket cmd, Func1 func, Boolean aopBefore, Boolean aopAfter) 0x3bbat FreeRedis.RedisClient.LogCall[T](CommandPacket cmd, Func1 func) 0x63at FreeRedis.RedisClient.PoolingAdapter.AdapterCall[TValue](CommandPacket, Func2) 0x9aat console_net8.Program.Main(String[] args) 0xa4at console_net8!BaseAddress0x2c67f0于是我系统的去看了官方aot文档发现文档太过于简陋反复看了七八遍也没有找到相关的解决内容。不得已扩大了搜索范围在谷歌搜索关键字 .net aot 花了近一个小时最终定位的关键字是 rd.xml配置相当简单只需要把FreeRedis的类型全部配置即可。
对应的 .csproj 内容如下
Project SdkMicrosoft.NET.SdkPropertyGroupOutputTypeExe/OutputTypeTargetFrameworknet8.0/TargetFrameworkPublishAotTrue/PublishAot/PropertyGroupItemGroupRdXmlFile Includerd.xml //ItemGroupItemGroupPackageReference IncludeFreeRedis Version1.2.5 //ItemGroup
/Project对应的 rd.xml 内容如下
DirectivesApplicationAssembly NameFreeRedis DynamicRequired All/Assembly/Application
/Directives重新发布后完美的解决所有问题.exe 文件体积增涨到 7兆。
这多亏当初设计FreeRedis的时候把依赖简单最低才这么容易支持更多的运行平台。 第二轮aot试验 FreeScheduler
FreeRedis对.net 8.0以及aot的支持完美收官这个时候已经凌晨三点咖啡的劲还很足。
我本身对FreeSql Aot是不抱希望的所以就去测试FreeScheduler了。
FreeScheduler支持三种存储方式内存/数据库/redis
基于内存毫无压力直接通过测试。得益于依赖较少
基于redis由于FreeRdis通过了aot测试基本不会有太大的问题记得设置好rd.xml顺利通过。
对应的 .csproj 如下
Project SdkMicrosoft.NET.Sdk.WebPropertyGroupTargetFrameworknet8.0/TargetFrameworkNullableenable/NullableImplicitUsingsenable/ImplicitUsingsInvariantGlobalizationtrue/InvariantGlobalizationPublishAottrue/PublishAot/PropertyGroupItemGroupRdXmlFile Includerd.xml //ItemGroupItemGroupProjectReference Include..\..\FreeScheduler\FreeScheduler.csproj //ItemGroup
/Project对应的 rd.xml 内容如下
DirectivesApplicationAssembly NameFreeScheduler DynamicRequired All/AssemblyAssembly NameFreeRedis DynamicRequired All/Assembly/Application
/DirectivesFreeScheduler还有一个web管理面板功能抱着尝试的态度试一试创建.net8.0自带的web API aot项目把有关代码加到项目的运行居然能直接通过太牛逼了这是我没有想到的。 对应 Program.cs
using FreeRedis;
using FreeScheduler;
using Newtonsoft.Json;var redis new RedisClient(127.0.0.1,poolsize10,exitAutoDisposePoolfalse);
redis.Serialize obj JsonConvert.SerializeObject(obj);
redis.Deserialize (json, type) JsonConvert.DeserializeObject(json, type);
redis.Notice (s, e)
{if (e.Exception ! null)Console.WriteLine(e.Log);
};
Scheduler scheduler new FreeSchedulerBuilder().OnExecuting(task {Console.WriteLine($[{DateTime.Now.ToString(HH:mm:ss.fff)}] {task.Topic} 被执行);task.Remark(log..);}).UseStorage(redis).Build();
if (Datafeed.GetPage(scheduler, null, null, null, null).Total 0)
{scheduler.AddTask([系统预留]清理任务数据, 86400, -1, 3600);scheduler.AddTaskRunOnWeek(周一武林大会, json, -1, 1:12:00:00);scheduler.AddTaskRunOnWeek(周日亲子活动, json, -1, 0:00:00:00);scheduler.AddTaskRunOnWeek(周六社交活动, json, -1, 6:00:00:00);scheduler.AddTaskRunOnMonth(月尾最后一天, json, -1, -1:16:00:00);scheduler.AddTaskRunOnMonth(月初第一天, json, -1, 1:00:00:00);scheduler.AddTask(定时20秒, json, 10, 20);scheduler.AddTask(测试任务1, json, new[] { 10, 30, 60, 100, 150, 200 });
}var builder WebApplication.CreateSlimBuilder(args);builder.Services.AddSingleton(scheduler);var app builder.Build();
var applicationLifeTime app.Services.GetServiceIHostApplicationLifetime();
applicationLifeTime.ApplicationStopping.Register(()
{scheduler.Dispose();redis.Dispose();
});
app.UseFreeSchedulerUI(/freescheduler/);app.Run();2023/11/16 04:23 127 appsettings.Development.json
2023/11/16 04:23 151 appsettings.json
2023/11/16 13:34 25,104,384 Examples_FreeScheduler_Net80_aot.exe
2023/11/16 13:34 238,948,352 Examples_FreeScheduler_Net80_aot.pdb
2023/11/16 13:31 31,208 FreeScheduler.pdbExamples_FreeScheduler_Net80_aot.exe 25兆流弊了双击运行它吧~~~~ 打开浏览器访问http://localhost:5000/freescheduler/ 意想不到连管理面板都支持 AOT这让我有了继续试验的动力~~~ aot试验意外收获 FreeSql
四点了还没犯困
最后抱着必凉的心态尝试终极试验FreeScheduler使用数据库持久化。
第一次失败报错在FreeSql内部这是是有TaskInterval类型不存在它其实是FreeScheduler程序集的并且rd.xml已经配置好了反复折腾仍然报错。
Unhandled Exception: System.NotSupportedException: FreeScheduler.TaskInterval[] is missing native code or metadata. This can happen for code that is not compatible with trimming or AOT. Inspect and fix trimming and AOT related warnings that were generated when the app was published. For more information see https://aka.ms/nativeaot-compatibilityat System.Reflection.Runtime.General.TypeUnifier.WithVerifiedTypeHandle(RuntimeArrayTypeInfo, RuntimeTypeInfo) 0x54at System.Array.InternalCreate(RuntimeType elementType, Int32 rank, Int32* pLengths, Int32* pLowerBounds) 0x64at System.Array.CreateInstance(Type elementType, Int32 length) 0x46at System.RuntimeType.GetEnumValues() 0x53at FreeSql.Internal.Utils.GetTableByEntity(Type entity, CommonUtils common) 0x138aat FreeSql.Internal.CommonProvider.CodeFirstProvider.SyncStructureb__51_0(CodeFirstProvider.TypeAndName a) 0x6eat System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext() 0x3fat System.Linq.Enumerable.WhereEnumerableIterator1.ToArray() 0x5cat FreeSql.Internal.CommonProvider.CodeFirstProvider.SyncStructure(CodeFirstProvider.TypeAndName[] objects) 0xd6at FreeSql.Internal.CommonProvider.CodeFirstProvider.SyncStructure[TEntity]() 0x6cat FreeScheduler.TaskHandlers.FreeSqlHandler..ctor(IFreeSql fsql) 0xf0at FreeSchedulerBuilder.Build() 0x2fat Program.Main$(String[] args) 0x180at Examples_FreeScheduler_Net80_aot!BaseAddress0xca7fc3从堆栈 GetEnumValues 可以看出是执行 Enum.GetValues 报错通过不断尝试中的其中一次在程序开始写了一行
Console.WriteLine(Enum.GetValues(typeof(TaskInterval)));
重新发布后又出现另一个错误大致与上面的相同只是类型变成了 TaskStatus同样加上一行代码
Console.WriteLine(Enum.GetValues(typeof(TaskStatus)));
又出现了另一个错误
Unhandled Exception: System.InvalidOperationException: The binary operator Equal is not defined for the types System.Reflection.Runtime.TypeInfos.NativeFormat.NativeFormatRuntimeNamedTypeInfo and System.Reflection.Runtime.TypeInfos.RuntimeConstructedGenericTypeInfo.at System.Linq.Expressions.Expression.GetEqualityComparisonOperator(ExpressionType, String, Expression, Expression, Boolean) 0x26bat System.Linq.Expressions.Expression.Equal(Expression, Expression, Boolean, MethodInfo) 0x63at FreeSql.Internal.Utils.GetDataReaderValueBlockExpressiong__LocalFuncGetExpression|65_0(Boolean ignoreArray, Utils.c__DisplayClass65_0) 0x3916at FreeSql.Internal.Utils.GetDataReaderValueBlockExpression(Type type, Expression value) 0x18dat FreeSql.Internal.Utils.c__DisplayClass66_0.GetDataReaderValueb__1(Type valueType2) 0x68at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey, Func2) 0xa4at FreeSql.Internal.Utils.GetDataReaderValue(Type type, Object value) 0x147at FreeSql.Internal.Utils.GetTableByEntity(Type entity, CommonUtils common) 0x145cat FreeSql.Internal.CommonProvider.CodeFirstProvider.SyncStructureb__51_0(CodeFirstProvider.TypeAndName a) 0x6eat System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext() 0x3fat System.Linq.Enumerable.WhereEnumerableIterator1.ToArray() 0x5cat FreeSql.Internal.CommonProvider.CodeFirstProvider.SyncStructure(CodeFirstProvider.TypeAndName[] objects) 0xd6at FreeSql.Internal.CommonProvider.CodeFirstProvider.SyncStructure[TEntity]() 0x6cat FreeScheduler.TaskHandlers.FreeSqlHandler..ctor(IFreeSql fsql) 0xf0at FreeSchedulerBuilder.Build() 0x2fat Program.Main$(String[] args) 0x1a8at Examples_FreeScheduler_Net80_aot!BaseAddress0xca8423这次使用 vs2022 附加进程的方式进行了调试深入 FreeSql 内部源码表达式树环境定位到了一行代码
Expression.Equal(type, Expression.Contrast(Guid?))把 Guid? 后面的问题去掉后再次发布。由于每次发布时间要20-30秒重试时间成本太高卡在这个问题已经有半个小时
2023/11/16 04:23 127 appsettings.Development.json
2023/11/16 04:23 151 appsettings.json
2023/11/16 13:52 29,018,112 Examples_FreeScheduler_Net80_aot.exe
2023/11/16 13:52 238,948,352 Examples_FreeScheduler_Net80_aot.pdb
2023/11/16 13:31 31,208 FreeScheduler.pdb
2021/11/03 01:47 1,763,632 SQLite.Interop.dll对于一个 web 项目并且包含 bootstrap 有关静态资源文件.exe 文件只有 29兆太满意了 看到控制台上的 SQL太惊喜了成功啦~~~~ 最后建议
从 .net6.0 到 .net8.0我们肉眼看不到变化实际微软做了很多内部工作在 aot 使用体验上明显能感知。
有人说信创国产运行那现在 aot 算什么
.net8.0 AOT 已经到了可用的阶段期待未来版本能改进以下问题
发布速度变快目前20-30秒一次实在太慢编译前检查错误而不是等发布后再报运行时错误加强调试.pdb 100兆 为何调试还都是 c 有关内容不能白瞎了这么大的调试文件啊尽快修复 Console.WriteLine(Enum.GetValues(typeof(TaskInterval))) 这个问题
我是开源人https://github.com/2881099
Native AOT apps have the following limitations:
No dynamic loading, for example, Assembly.LoadFile.No run-time code generation, for example, System.Reflection.Emit.No C/CLI.Windows: No built-in COM.Requires trimming, which has limitations.Implies compilation into a single file, which has known incompatibilities.Apps include required runtime libraries (just like self-contained apps, increasing their size as compared to framework-dependent apps).System.Linq.Expressions always use their interpreted form, which is slower than run-time generated compiled code.Not all the runtime libraries are fully annotated to be Native AOT compatible. That is, some warnings in the runtime libraries aren’t actionable by end developers. 文章转载自: http://www.morning.stbhn.cn.gov.cn.stbhn.cn http://www.morning.dwfxl.cn.gov.cn.dwfxl.cn http://www.morning.tsqpd.cn.gov.cn.tsqpd.cn http://www.morning.xbptx.cn.gov.cn.xbptx.cn http://www.morning.dhmll.cn.gov.cn.dhmll.cn http://www.morning.ummpdl.cn.gov.cn.ummpdl.cn http://www.morning.hlppp.cn.gov.cn.hlppp.cn http://www.morning.kpbq.cn.gov.cn.kpbq.cn http://www.morning.gstg.cn.gov.cn.gstg.cn http://www.morning.tblbr.cn.gov.cn.tblbr.cn http://www.morning.zryf.cn.gov.cn.zryf.cn http://www.morning.fhrt.cn.gov.cn.fhrt.cn http://www.morning.pmftz.cn.gov.cn.pmftz.cn http://www.morning.taojava.cn.gov.cn.taojava.cn http://www.morning.wclxm.cn.gov.cn.wclxm.cn http://www.morning.hrdx.cn.gov.cn.hrdx.cn http://www.morning.brtxg.cn.gov.cn.brtxg.cn http://www.morning.ccffs.cn.gov.cn.ccffs.cn http://www.morning.lpskm.cn.gov.cn.lpskm.cn http://www.morning.yydzk.cn.gov.cn.yydzk.cn http://www.morning.lhygbh.com.gov.cn.lhygbh.com http://www.morning.yqyhr.cn.gov.cn.yqyhr.cn http://www.morning.fsjcn.cn.gov.cn.fsjcn.cn http://www.morning.ykrg.cn.gov.cn.ykrg.cn http://www.morning.zrgsg.cn.gov.cn.zrgsg.cn http://www.morning.hcrxn.cn.gov.cn.hcrxn.cn http://www.morning.njftk.cn.gov.cn.njftk.cn http://www.morning.ldgqh.cn.gov.cn.ldgqh.cn http://www.morning.rpth.cn.gov.cn.rpth.cn http://www.morning.nmrtb.cn.gov.cn.nmrtb.cn http://www.morning.sfwd.cn.gov.cn.sfwd.cn http://www.morning.trnhy.cn.gov.cn.trnhy.cn http://www.morning.lzsxp.cn.gov.cn.lzsxp.cn http://www.morning.wnhml.cn.gov.cn.wnhml.cn http://www.morning.lddpj.cn.gov.cn.lddpj.cn http://www.morning.gbybx.cn.gov.cn.gbybx.cn http://www.morning.hffjj.cn.gov.cn.hffjj.cn http://www.morning.ftmzy.cn.gov.cn.ftmzy.cn http://www.morning.llqky.cn.gov.cn.llqky.cn http://www.morning.pwxkn.cn.gov.cn.pwxkn.cn http://www.morning.drspc.cn.gov.cn.drspc.cn http://www.morning.rnnwd.cn.gov.cn.rnnwd.cn http://www.morning.kjtdy.cn.gov.cn.kjtdy.cn http://www.morning.rwbh.cn.gov.cn.rwbh.cn http://www.morning.sfsjh.cn.gov.cn.sfsjh.cn http://www.morning.krdb.cn.gov.cn.krdb.cn http://www.morning.rjnky.cn.gov.cn.rjnky.cn http://www.morning.qnbgk.cn.gov.cn.qnbgk.cn http://www.morning.ctlbf.cn.gov.cn.ctlbf.cn http://www.morning.jyzqn.cn.gov.cn.jyzqn.cn http://www.morning.nqgds.cn.gov.cn.nqgds.cn http://www.morning.hgsylxs.com.gov.cn.hgsylxs.com http://www.morning.feites.com.gov.cn.feites.com http://www.morning.kehejia.com.gov.cn.kehejia.com http://www.morning.nkhdt.cn.gov.cn.nkhdt.cn http://www.morning.zcnfm.cn.gov.cn.zcnfm.cn http://www.morning.xmhpq.cn.gov.cn.xmhpq.cn http://www.morning.c7617.cn.gov.cn.c7617.cn http://www.morning.mlpmf.cn.gov.cn.mlpmf.cn http://www.morning.xrlwr.cn.gov.cn.xrlwr.cn http://www.morning.wglhz.cn.gov.cn.wglhz.cn http://www.morning.syxmx.cn.gov.cn.syxmx.cn http://www.morning.drnfc.cn.gov.cn.drnfc.cn http://www.morning.mzcrs.cn.gov.cn.mzcrs.cn http://www.morning.frfnb.cn.gov.cn.frfnb.cn http://www.morning.qqpg.cn.gov.cn.qqpg.cn http://www.morning.wckrl.cn.gov.cn.wckrl.cn http://www.morning.ccffs.cn.gov.cn.ccffs.cn http://www.morning.qfdmh.cn.gov.cn.qfdmh.cn http://www.morning.tfpqd.cn.gov.cn.tfpqd.cn http://www.morning.kmwbq.cn.gov.cn.kmwbq.cn http://www.morning.txfzt.cn.gov.cn.txfzt.cn http://www.morning.stwxr.cn.gov.cn.stwxr.cn http://www.morning.kqxwm.cn.gov.cn.kqxwm.cn http://www.morning.jcyyh.cn.gov.cn.jcyyh.cn http://www.morning.tkryt.cn.gov.cn.tkryt.cn http://www.morning.xdmsq.cn.gov.cn.xdmsq.cn http://www.morning.xqqcq.cn.gov.cn.xqqcq.cn http://www.morning.kzrbd.cn.gov.cn.kzrbd.cn http://www.morning.mmxt.cn.gov.cn.mmxt.cn