我正在尝试运行 Azure 函数,但在部署时遇到以下错误 --
Microsoft.Azure.WebJobs.Script: Error building configuration in an external startup class.
System.Private.CoreLib: Could not load file or assembly '<MyAssembly>, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null'.
但是我部署成功了,我可以在App Files中看到DLL。我在 Functions v4.0 上运行 C#/.net 6.0,并使用 Deployment Center 生成的 GitHub Workflow 操作进行部署。
什么会导致运行时看不到主函数DLL?
添加应用程序文件的图像:
我的项目包参考:
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.8.2" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.5.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.15.1" />
<PackageReference Include="Cosmonaut" Version="2.11.3" />
<PackageReference Include="Cosmonaut.ApplicationInsights" Version="2.1.1" />
<PackageReference Include="Cosmonaut.Extensions.Microsoft.DependencyInjection" Version="2.3.0" />
<PackageReference Include="Cosmonaut.NestedQueries" Version="2.11.4" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="6.0.0" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.6.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.SendGrid" Version="3.0.3" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.6.3" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
</ItemGroup>
从部署中心部署 GitHub 操作:
# Docs for the Azure Web Apps Deploy action: https://github.com/azure/functions-action
# More GitHub Actions for Azure: https://github.com/Azure/actions
name: Build and deploy dotnet core app to Azure Function App - brokentoysapi3
on:
push:
branches:
- master
workflow_dispatch:
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: './api/_new/BrokenToys.Api/' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '6.0.x' # set this to the dotnet version to use
jobs:
build-and-deploy:
runs-on: windows-latest
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v2
- name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: 'Resolve Project Dependencies Using Dotnet'
shell: pwsh
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
dotnet build --configuration Release --output ./output
popd
- name: 'Run Azure Functions Action'
uses: Azure/functions-action@v1
id: fa
with:
app-name: 'brokentoysapi3'
slot-name: 'Production'
package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_E20EFE8EF7D84C4AA5B5C75BE0B66D0F }}
Microsoft.Azure.WebJobs.Script:在外部启动类中构建配置时出错。 System.Private.CoreLib:无法加载文件或程序集',Version=1.0.0.0,Culture=neutral,PublicKeyToken=null'。
此错误表明运行时无法为您的函数加载程序集。这可能是由于一些原因造成的,例如文件路径不正确或函数名称不正确。 检查以下步骤是否有助于解决问题:
验证错误消息中程序集的名称和版本与 App Files 文件夹中程序集的名称和版本相匹配。如果它们不匹配,您可能需要重建项目并重新部署它。
检查程序集是否位于 App Files 文件夹中的正确位置。它应该位于函数应用程序根目录下的 bin 文件夹中。
检查程序集是否与函数的运行时版本兼容,并检查函数应用是否配置为在 Azure 门户中使用正确版本的运行时。
检查您的 GitHub Workflow 操作是否已正确配置以部署您的函数应用程序。确保它正在部署所有文件都被部署到正确的位置。
我在我的环境中复制了相同的内容,并且它没有任何问题,如下所示:
DLL文件:
我还观察到您在应用程序中使用的包
Microsoft.Azure.WebJobs.Script
已被弃用。