在 Rider 或 VS 2022 中本地运行我们的 Azure 函数应用程序突然停止工作并出现以下错误:

此版本的 Azure Functions Core Tools 要求你的项目引用 Microsoft.NET.Sdk.Functions 4.5.0 或更高版本。请更新到最新版本。

我们之前使用的是 4.0.1 版,并通过 Nuget 更新到 4.5 版。但是我们仍然无法运行该应用程序。

从 VS 2022 弹出消息:没有与项目中指定的版本匹配的可用函数运行时。

从 Rider 中,我们得到与之前相同的消息:

此版本的 Azure Functions Core Tools 要求你的项目引用 Microsoft.NET.Sdk.Functions 4.5.0 或更高版本。

有什么建议吗?

谢谢!

csproj 文件

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <AzureFunctionsVersion>V4</AzureFunctionsVersion>
    </PropertyGroup>
    <PropertyGroup>
        <_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
    </PropertyGroup>
    <ItemGroup>
      <Compile Remove="ExpirationList.cs" />
    </ItemGroup>
    <ItemGroup>
        <FrameworkReference Include="Microsoft.AspNetCore.App" />
        <PackageReference Include="Azure.Identity" Version="1.12.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
        <PackageReference Include="Microsoft.Graph" Version="5.56.0" />
        <PackageReference Include="Microsoft.Graph.Core" Version="3.1.12" />
        <PackageReference Include="Microsoft.Identity.Client" Version="4.61.3" />
        <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.5.0" />
        <PackageReference Include="Syncfusion.Pdf.Net.Core" Version="26.2.5" />
        <PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="26.2.5" />
    </ItemGroup>
    <ItemGroup>
        <None Update="host.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Update="local.settings.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <CopyToPublishDirectory>Never</CopyToPublishDirectory>
        </None>
    </ItemGroup>
    <ItemGroup>
      <ProjectReference Include="..\Asap.Mgmt.WebApi.Data\Asap.Mgmt.WebApi.Data.csproj" />
      <ProjectReference Include="..\OidcApiAuthorization\OidcApiAuthorization.csproj" />
    </ItemGroup>
</Project>

================ 示例函数

public class AgendaApi
    {
        private readonly IApiAuthorization _apiAuthorization;
        private readonly IConfigurationRoot _config;
        UtilRepository _util;
        public AgendaApi(IApiAuthorization apiAuthorization)
        {
            _apiAuthorization = apiAuthorization;

            _config = new ConfigurationBuilder()
                .AddJsonFile("local.settings.json", true)
                .AddEnvironmentVariables()
                .Build();
            _util = new UtilRepository();
        }


        [FunctionName("GenerateAgenda2")]
        public async Task<IActionResult> GenerateAgenda2(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "agenda/generateagenda2/hearing/{hearingid}")]
                    HttpRequest req, ILogger log, ExecutionContext context, int hearingid)
        {
            log.LogInformation("Reports - Generate Agenda 2");

            var repo = new AgendaRepository(_config, log, _util);
            var (fileContent, contentType) = await repo.GenerateAgenda2(hearingid);
            return new FileStreamResult(fileContent, contentType);
        }
    }
}

6

  • 我应该提到,该函数应用程序是 .Net 6.0


    – 

  • 请分享你的.csproj 文件和函数代码


    – 

  • 嗨,Ikhtesam。谢谢你的帮助。你的意思是添加一个 api 方法的示例吗?


    – 

  • 我刚刚遇到了同样的事情,这对我有用


    – 

  • 请分享您的功能代码


    – 


最佳答案
1

您需要专门为该项目更新 Microsoft.NET.Sdk.Functions。进入函数项目的文件夹(不是解决方案,而是实际项目)并在那里打开一个 powershell 窗口。然后运行:dotnet add package Microsoft.NET.Sdk.Functions --version 4.5.0

1

  • 嗨,Wesley。非常感谢。我按照你的建议做了,但仍然弹出窗口:“没有与项目中指定的版本匹配的可用函数运行时。”


    –