.NET AOT 参数

2022年10月8日 2158点热度 2人点赞 0条评论
内容目录

项目发布参数:

dotnet publish -c Release -r win-x64 -p:PublishProfile=FolderProfile  --no-self-contained
dotnet publish -c Release -r win-x64 -p:PublishProfile=FolderProfile -p:PublishReadyToRun=true -p:PublishTrimmed=true --self-contained false

file

开启裁剪:
file
file
file

关闭反射:

<IlcDisableReflection>true</IlcDisableReflection>

file

添加 Nuget 包引用:

    <ItemGroup>
        <PackageReference Include="Microsoft.DotNet.ILCompiler" Version="7.0.0-*" />
    </ItemGroup>

其它配置:

  <TrimMode>full</TrimMode>
  <RunAOTCompilation>True</RunAOTCompilation>
  <PublishTrimmed>true</PublishTrimmed>
  <PublishAot>true</PublishAot>
  <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>

PublishAot 需要在 .NET 7 下使用。

简单的配置:

        <!-- 发布相关-->
        <PublishSingleFile>true</PublishSingleFile>
        <SelfContained>false</SelfContained>
        <RuntimeIdentifier>win-x64</RuntimeIdentifier>

        <!-- AOT 相关-->
        <TrimMode>full</TrimMode>
        <RunAOTCompilation>True</RunAOTCompilation>
        <PublishTrimmed>true</PublishTrimmed>
        <PublishAot>true</PublishAot>
        <IlcDisableReflection>true</IlcDisableReflection>

痴者工良

高级程序员劝退师

文章评论