本機調試 Azure Functions 與 IronPDF
This article was translated from English: Does it need improvement?
TranslatedView the article in English
在本地運行 Azure 時遇到的問題
常見的異常情況是遇到此問題時會出現“在定位部署配置文件 IronPdf.Native.Chrome.deployment.json 時出錯”。
推薦: 在以 .NET Core 3.1 為目標的 Windows 托管 Azure Function Apps 上運行。
**必須:** 在 Visual Studio 中創建 Azure Function 時,使用預設的**「進程內」**配置。 IronPDF 的最新版本支援在「外部處理程序」或「隔離處理程序」中運行的 Azure Functions,如此處所述[在隔離工作模型中運行C# Azure Functions的指南](https://docs.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide#differences-with-net-class-library-functions)然而,較舊版本可能不支持這類型的 Azure Functions。

## 在本地運行 Azure Functions 時遇到的依賴性問題
在本地運行 Azure 時,使用 Azurite(VS2022)或 Azure Storage 模擬器(VS2019)在Storage Emulator使用的部署中,會創建一個額外的bin目錄。 僅有 DLL 檔案被複製到此目錄中,因此需要額外檔案的軟體將無法運作,並可能拋出上述異常。
您可以通過將 runtimes 目錄複製到 Storage Emulator 使用的單獨 bin 目錄中來解決此問題。 我們建議將此作為**後置建置事件**(見下方指示)在本地運行時(由於重新編譯/構建將使 bin 目錄恢復到其原始狀態)部署到雲端時,您將不會遇到此問題。
- **問題:**在本地運行 Azure Function 項目時,它會創建一個額外的 _bin_ 文件夾,並從該文件夾運行函數。 但是,它並未將所有必要的檔案複製到所述的 _bin_ 資料夾中。
- **範例:** 在 _C:\code\azure-functions-test_ 的項目,建置至 _C:\code\azure-functions-test\bin\Debug\netcoreapp3.1_
- **解決方案:** 複製 _C:\code\azure-functions-test\bin\Debug\netcoreapp3.1\runtimes_ 目錄,使其也存在於 _C:\code\azure-functions-test\bin\Debug\netcoreapp3.1\bin_ 中。
- 如有提示,覆寫任何現有檔案

## 建置後事件
1. 在 Azure Functions 專案上點擊右鍵,選擇**屬性**
2. 向下滑動至**活動**部分
3. 輸入一個 **Post-build 事件** 的 `XCOPY "$(目標目錄)運行時" "$(目標目錄)bin/runtimes" /S /E /Y /I /R /D`
