使用 ReadyToRun 或 Ahead-Of-Time (AOT) 編譯
This article was translated from English: Does it need improvement?
TranslatedView the article in English
.NET ReadyToRun (R2R)是一種預先編譯 (AOT) 形式。
在部署期間啟用 ReadyToRun 編譯可能會違反篡改保護機制,並導致以下異常:
Exception: Unhandled exception. IronSoftware.Exceptions.LicensingException: IronPdf, Version=2024.2.0.2, Culture=neutral, PublicKeyToken=94e1c31412563c75 assembly is not authentic. Please try to reinstall the nuget package
at IronPdf.PdfDocument.uswvws(Boolean vhfwdf)
at IronPdf.PdfDocument.get_BinaryData()
at IronPdf.PdfDocument.SaveAs(String FileName, Boolean SaveAsRevision)
at Program.<Main>(String[] args) in C:\csharppro\aottest\aottest\Program.cs:line 5原因
根據微軟的文檔,SDK 將預先編譯隨應用程式一起分發的組件。 對於獨立應用程序,這組程序集將包含框架。 需要注意的是,C++/CLI 二進位檔案不符合 ReadyToRun 編譯的條件。
解決方案
若要從 ReadyToRun 處理中排除特定程序集,請使用<PublishReadyToRunExclude>在專案文件中列出。例如,要排除IronPdf.dll程式集:
<ItemGroup>
<!-- Excludes IronPdf.dll from ReadyToRun compilation -->
<PublishReadyToRunExclude Include="IronPdf.dll" />
</ItemGroup><ItemGroup>
<!-- Excludes IronPdf.dll from ReadyToRun compilation -->
<PublishReadyToRunExclude Include="IronPdf.dll" />
</ItemGroup>XML
應將此 XML 程式碼片段新增至您的專案檔案 ( .csproj ) 中,以防止使用 ReadyToRun 預先編譯指定的組件,從而避免潛在的許可或篡改問題。
準備好開始了嗎?
Nuget 下載 17,012,929 | 版本: 2025.12 剛剛發布






