We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
正确标记裁剪不兼容的 API 或为其补充给 ILC 的类型使用信息以消除编译期(发布期)产生的 ILC 警告
虽然 FreeSql 声明自己支持 AOT,但是在发布期产生的 ILXXXX 警告通常代表 ILC 无法确保给定的 API 在经过裁剪后能够正常运作;所以在源码中对这些依赖动态特性的API进行标注是很重要的,因为这些额外的 Attribute 能够帮助 ILC 决定要保留哪些类型或类型的成员(以使得原本经过裁剪导致错误的API变得可用),以及用户是否使用了根本无法在AOT环境调用的API(以确保AOT发布失败来避免用户获得本就不可用的应用程序)
可以查看 准备 .NET 库以进行剪裁 文档以获取更多和裁剪 / 正确支持AOT相关的信息
对 .Net 应用程序进行 AOT 编译时
我编写了一个极小的 C# AOT Minimal API 应用程序以检查常见 API 的使用情况,此项目在发布时会产生若干 IL 警告
using System.Text.Json.Serialization; using FreeSql; using FreeSql.DataAnnotations; using Microsoft.AspNetCore.Mvc; using DataType = FreeSql.DataType; var builder = WebApplication.CreateSlimBuilder(args); builder.Services.ConfigureHttpJsonOptions(option => option.SerializerOptions.TypeInfoResolver = ApplicationJsonContext.Default); builder.Services.AddSingleton<IFreeSql>(_ => new FreeSqlBuilder() // .UseAdoConnectionPool(true) .UseConnectionString(DataType.Sqlite, "data source=application_data.db") // .UseMonitorCommand(cmd => Console.WriteLine($"SqlCommand:\n{cmd.CommandText}")) .UseAutoSyncStructure(true) .Build() ); var app = builder.Build(); app.MapGet("/add", async ([FromHeader(Name = nameof(name))] string name, [FromHeader(Name = nameof(score))] int score, IFreeSql sql) => { await sql.InsertOrUpdate<LeaderBoardItem>().SetSource(new LeaderBoardItem(name, score)).ExecuteAffrowsAsync(); return Results.Ok(); }); app.MapGet("/check", (IFreeSql sql) => sql.Select<LeaderBoardItem>().ToListAsync()); app.Run(); [JsonSerializable(typeof(List<LeaderBoardItem>))] internal partial class ApplicationJsonContext : JsonSerializerContext; internal record LeaderBoardItem( [property: Column(IsPrimary = true)] string Name, int Score );
Expression.Lambda()
DynamicallyAccessedMembers
GetType().GetMethods()
MakeGenericType()
Expression.Property(expr, "Name")
Assembly.Location
The text was updated successfully, but these errors were encountered:
IsTrimmable
IsAotCompatible
No branches or pull requests
Feature 特性
正确标记裁剪不兼容的 API 或为其补充给 ILC 的类型使用信息以消除编译期(发布期)产生的 ILC 警告
简要描述原因
虽然 FreeSql 声明自己支持 AOT,但是在发布期产生的 ILXXXX 警告通常代表 ILC 无法确保给定的 API 在经过裁剪后能够正常运作;所以在源码中对这些依赖动态特性的API进行标注是很重要的,因为这些额外的 Attribute 能够帮助 ILC 决定要保留哪些类型或类型的成员(以使得原本经过裁剪导致错误的API变得可用),以及用户是否使用了根本无法在AOT环境调用的API(以确保AOT发布失败来避免用户获得本就不可用的应用程序)
可以查看 准备 .NET 库以进行剪裁 文档以获取更多和裁剪 / 正确支持AOT相关的信息
使用场景
对 .Net 应用程序进行 AOT 编译时
亟待解决的 IL 错误汇总
我编写了一个极小的 C# AOT Minimal API 应用程序以检查常见 API 的使用情况,此项目在发布时会产生若干 IL 警告
Expression.Lambda()
DynamicallyAccessedMembers
注解的反射GetType().GetMethods()
MakeGenericType()
Expression.Property(expr, "Name")
Assembly.Location
The text was updated successfully, but these errors were encountered: