.NET 7:从 Visual Studio Code 本地运行/调试 Azure Function(作为独立进程)

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

我使用以下 - 非常简单 - Program.cs 创建了一个 AZ 功能项目:

var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
    .Build();

host.Run();

public partial class Program { }

下一个-虚拟-函数:

[Function("RabbitMQFunction")]
    public void Run
    (
        [RabbitMQTrigger("EmailQueue", ConnectionStringSetting = "xxx:xxx:services:infraestructure:emailservice:rabbitmq")] string item,
        FunctionContext context)
    {
        var logger2 = context.GetLogger("RabbitMQFunction");
        logger2.LogInformation($"Output message created at {DateTime.Now}");
    }

local.settings.json:

{
    "ConnectionStrings": {
        "xxx:xxx:services:infraestructure:emailservice:rabbitmq": "connection_string"
    },
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
    }
}

主机.json:

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            }
        }
    }
}

属性 > launchSettings.json:

{
  "profiles": {
    "xxx_xxx_Services_Infrastructure_EmailService": {
      "commandName": "Project",
      "commandLineArgs": "--port 7246",
      "launchBrowser": false
    }
  }
}

我可以从命令行使用 func start 毫无问题地运行该函数(我已经安装了 Azure Functions Core Tools),但是当我尝试从 vscode 运行/调试该函数时,会引发以下异常:

Exception has occurred: CLR/System.InvalidOperationException An exception of type 'System.InvalidOperationException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'The gRPC channel URI 'http://:63205' could not be parsed.' at Microsoft.Extensions.DependencyInjection.GrpcServiceCollectionExtensions.<>c.<AddGrpc>b__1_1(IServiceProvider p) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context) at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument) at ...
接下来我可以尝试什么?

c# .net visual-studio-code azure-functions xunit
1个回答
0
投票
在 AZURE -> WORKSPACE -> Local Project 下选择“Initialize Project for Use with VS Code...”,或使用命令选项板(Mac 上为 Shift+Cmd+P,Windows 上为 Shift+Ctrl+P)并执行命令Azure Functions:初始化项目以与 VS Code 一起使用...

这将“将所需的 Visual Studio Code 项目文件添加到现有的 Functions 项目中。使用此命令可处理您使用 Core Tools 创建的项目。”

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