Dotnet8 隔离的 Mac Visual studio 2022 - 无法运行 Azure 函数

问题描述 投票:0回答:1

在我使用 Windows 之前,我切换到了 Mac。 我正在尝试使用 Azure 函数设置项目并在本地运行它。

我收到错误“无法执行“path.functionname.exe”” Cannot execute exe

所有 nuget 软件包均已更新并已恢复。我尝试清理 bin 文件夹 - 不成功

.Net SDK 版本 8 func - 版本 4.0.3687

SDK version

项目设置:

触发:

using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
using System;

namespace SchedulesFunction.Triggers
{
    public class SchedulesTrigger
    {
        [Function("SchedulesTrigger")]
        public void Run([TimerTrigger("0 */5 * * * *")] TimerInfo myTimer, ILogger log)
        {
            log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        }
    }
}

.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
  </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.3.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.2" />
        <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.2.0" />
    </ItemGroup>
    <ItemGroup>
    </ItemGroup>
    <ItemGroup>
      <None Remove="Configuration\" />
    </ItemGroup>
    <ItemGroup>
      <None Include="local.settings.json">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        <CopyToPublishDirectory>Never</CopyToPublishDirectory>
      </None>
    </ItemGroup>
    <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
    <ItemGroup>
      <Folder Include="Configuration\" />
    </ItemGroup>
    <ItemGroup>
      <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
    </ItemGroup>
</Project>

程序.cs

using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .ConfigureServices(services =>
    {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
    })
    .Build();

host.Run();

本地.settings.json

{
  "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
    }
 }

我尝试更新SDK版本 我将设置更改为始终使用 8 SDK(如果可用) 什么都不起作用。我无法在 mac 上本地运行 azure 函数

c# macos visual-studio azure-functions sdk
1个回答
0
投票

.NET 8 SDK 未正确下载到您的系统上。点击此链接下载适用于 macOS 的 .NET SDK 并检查路径。完成安装过程后,请确保重新启动 Visual Studio。

我尝试了下面的示例定时器触发功能。

代码:

using System;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;

namespace FunctionApp109
{
    public class SchedulesTrigger
    {
        private readonly ILogger<SchedulesTrigger> _logger;
        public SchedulesTrigger(ILogger<SchedulesTrigger> logger)
        {
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));
        }
        [Function("SchedulesTrigger")]
        public void Run([TimerTrigger("0 */4 * * * *")] TimerInfo myTimer)
        {
            _logger.LogInformation($"Timer trigger function ran successfully at : {DateTime.Now}");
        }
    }
}

.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Timer" Version="4.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
  </ItemGroup>
</Project>

输出:

Timer触发函数运行成功如下。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.