AOT技术的好处:
提升启动速度;
降低发布包的大小;
内存占用小;
编译为字节码反编译难度加大;
项目配置
<PropertyGroup> <RuntimeIdentifier>win-x86;win-x64;osx-x64;linux-x64</RuntimeIdentifier> <!-- 根据需要设置 --> <PublishSingleFile>true</PublishSingleFile> <PublishTrimmed>true</PublishTrimmed> <!-- 可选,启用去除未使用的库 --> <PublishReadyToRun>true</PublishReadyToRun> <!-- 启用ReadyToRun --> <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract> <!-- 包含本地依赖 --> </PropertyGroup>
常规发布命令 dotnet publish -r linux-arm64 -c Release AOT发布(-p:PublishAot=true 参数) dotnet publish -r linux-arm64 -c Release -p:PublishAot=true
然后通过以下命令发布项目,生成链接库:
dotnet publish -p:NativeLib=Shared -r win-x64 -c Release
指定项目
dotnet publish -p:Project=./MyProject/MyProject.csproj
指定解决方案
dotnet publish ./MySolution.sln
体积裁剪配置
在csproj 文件加入以下配置: <!--AOT 相关--> < PublishAot> true </ PublishAot> < TrimMode> full </ TrimMode> < RunAOTCompilation> True </ RunAOTCompilation> < PublishTrimmed> true </ PublishTrimmed> < TrimmerRemoveSymbols> true </ TrimmerRemoveSymbols> < PublishReadyToRunEmitSymbols> false </ PublishReadyToRunEmitSymbols> < DebuggerSupport> false </ DebuggerSupport> < EnableUnsafeUTF7Encoding> true </ EnableUnsafeUTF7Encoding> < InvariantGlobalization> true </ InvariantGlobalization> < HttpActivityPropagationSupport> false </ HttpActivityPropagationSupport> < MetadataUpdaterSupport> true </ MetadataUpdaterSupport> < UseSystemResourceKeys> true </ UseSystemResourceKeys> < IlcDisableReflection> true </ IlcDisableReflection>
非aot调用aot库
aot调用aot库
参考:https://www.sohu.com/a/604546825_121124363
标签:技术,publish,x64,aot,AOT,NET8,dotnet,true From: https://www.cnblogs.com/thingk/p/18267924