2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Azure Functions Host をローカル VS Code でデバッグ実行したときのメモ

Posted at

目的

Azure Functions をローカル環境でステップ実行したい。

言語ワーカー上での関数アプリコード実行を経て、Functions Host 上でどのように動作しているのか確認したり、独自の OutputBinding を作ったりするときに役立つと思います。

免責

この記事は単なる動かしてみたメモであり、オフィシャルな方法ではありません。

VS Code でのデバッグ実行方法

launch.json

すべてはここに書いてある
https://github.com/Azure/azure-functions-host/blob/dev/.vscode/launch.json

launch.json
{
  // Use IntelliSense to find out which attributes exist for C# debugging
  // Use hover for the description of the existing attributes
  // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
  "version": "0.2.0",
  "configurations": [
    {
      "name": ".NET Core Launch (web)",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      // If you have changed target frameworks, make sure to update the program path.
      "program": "${workspaceFolder}/src/WebJobs.Script.WebHost/bin/Debug/net6.0/Microsoft.Azure.WebJobs.Script.WebHost.dll",
      "args": [],
      "cwd": "${workspaceFolder}/sample/Node",
      "stopAtEntry": false,
      // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
      "serverReadyAction": {
        "action": "openExternally",
        "pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
      },
      "env": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "AZURE_FUNCTIONS_ENVIRONMENT": "Development",
        "AzureWebJobsSecretStorageType": "Files"
      },
      "sourceFileMap": {
        "/Views": "${workspaceFolder}/Views"
      }
    },
    {
      "name": ".NET Core Attach",
      "type": "coreclr",
      "request": "attach",
      "processId": "${command:pickProcess}"
    }
  ]
}

デバッグ実行するとどうなるか

この状態で、Functions Host のメインコードに対してブレークポイントが有効な状態で起動できる。

image.png

関数コードはどこから読み込まれるか

"cwd": "${workspaceFolder}/sample/Node", に記載のディレクトリつまり、リポジトリ内の sample/Nodeをアプリケーションコードとしてロードして、Functions Host が起動する。

ただし、デフォルトでは、以下のようにバインディング拡張が読み込まれず、単純な HTTP トリガー関数しか動作確認ができない模様です。

image.png

自分の関数コードを利用したい

その場合は、cwd にアプリケーションコードの host.json があるディレクトリを指定します。
手っ取り早いのは、sample/Node と同じ階層に作っちゃって sample/MyApp とするのがよいかと思います。

AppSettingsを指定したい

そのままではlocal.settings.json は読み込まれないようです。
launch.jsonenv に記載しておけば読み込まれました。

image.png

extensionBundle がロードされない

通常、host.json に extensionBundle を指定しておくことで、.NET in-process 以外の言語を利用する場合に拡張機能が利用できるようになりますが、指定してもうまくロードしてくれませんでした。

代替案として、アプリコードディレクトリ内で func extensions install --package を実行し、.csproj ファイルを作成しておく必要がありました。

参考資料

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?