使用 VS Code 调试 (F5) Azure Functions 时启动 Azurite

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

有谁知道在 VS Code 中进行 F5 调试时,是否有一种简单、推荐的方法始终使用临时目录在后台启动/停止 Azurite,就像 Visual Studio 本身所做的那样,也许通过 launch.json?我安装了 Azurite,因此我可以手动启动该服务并且它可以工作,但我发现项目目录中的所有

__*__
文件真的很烦人。更不用说
Azurite: Clean
命令 never 由于文件级锁定而清除所有内容。我的环境是最新的,目前如下:

  • 操作系统:Windows 11 23H2(操作系统内部版本 22631.3527)
  • VS 代码:1.89.1(带有 Azure、Azure Functions 和 Azurite 扩展)
  • Azure 函数核心工具:4.0.5700
  • 型号:dotnet-isolated
  • 语言:C#
  • local.settings.json 包含“AzureWebJobsStorage”:“UseDevelopmentStorage=true”
visual-studio-code azure-functions azure-functions-core-tools azurite
1个回答
0
投票

我已按照以下步骤创建了 .NET8 隔离 Blob 触发器 Azure 函数,并且能够在不手动运行 Azurite 的情况下运行该函数,还可以避免创建额外的

(__*__)
文件。

  • 在 Visual Studio Code 中打开命令面板(Ctrl+shift+p),选择
    Azure Functions: Create Function

enter image description here

  • 选择项目文件夹、运行时和函数触发器。

enter image description here

  • 选择
    Use Azurite Emulator for local storage

enter image description here

函数创建成功。

local.settings.json:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
  }
}
  • 开始调试该功能,这将成功运行,而无需在项目文件夹中创建任何额外文件。

输出:

Executing task: C:\Program Files\dotnet\dotnet.exe build /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary 

MSBuild version 17.9.8+b34f75857 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  functionapp2 -> C:\Users\uname\Source\Repos\functionapp2\bin\Debug\net8.0\functionapp2.dll
  Determining projects to restore...
  Restored C:\Users\uname\AppData\Local\Temp\dba1mmm5.sng\WorkerExtensions.csproj (in 1.66 sec).
  WorkerExtensions -> C:\Users\uname\AppData\Local\Temp\dba1mmm5.sng\buildout\Microsoft.Azure.Fu
  nctions.Worker.Extensions.dll
 *  Terminal will be reused by tasks, press any key to close it. 

 *  Executing task: func host start 

Azure Functions Core Tools
Core Tools Version:       4.0.5700 Commit hash: N/A +71cc84964a60bfb07d95839b7c666bd239507bdd (64-bit)  
Function Runtime Version: 4.33.2.22572

[2024-05-14T12:16:01.703Z] Found C:\Users\uname\Source\Repos\functionapp2\functionapp2.csproj. Using fing for user secrets file configuration.
[2024-05-14T12:16:19.544Z] Worker process started and initialized.

Functions:

        BlobTrigger1: blobTrigger

For detailed output, run func with --verbose flag.
[2024-05-14T12:16:22.956Z] Executing 'Functions.BlobTrigger1' (Reason='New blob detected(LogsAndContainerScan): samples-workitems/Helloworld.txt', Id=f6aa2108-0112-4cc1-9faf-3bc8b892171d)
[2024-05-14T12:16:22.967Z] Trigger Details: MessageId: 48c33c25-80dc-40b6-977b-75ccee932de9, DequeueCount: 1, InsertedOn: 2024-05-14T12:16:22.000+00:00, BlobCreated: 2024-05-14T11:56:05.000+00:00, BlobLastModified: 2024-05-14T11:56:05.000+00:00
[2024-05-14T12:16:23.708Z] C# Blob trigger function Processed blob
 Name: Helloworld.txt
 Data:
[2024-05-14T12:16:23.796Z] Executed 'Functions.BlobTrigger1' (Succeeded, Id=f6aa2108-0112-4cc1-9faf-3bc8b892171d, Duration=975ms)
[2024-05-14T12:16:24.440Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'. 

enter image description here

文件夹结构:

enter image description here

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