9

Using .NET Core on a Mac with Visual Studio Code, I'm trying to host an Azure Function locally, and attach the debugger to it. Manually, I can get it to work by starting the function with func host start, followed by pressing the debug button in the IDE, which runs the default launch.json file. This let's me pick a process to attach the debugger to because of the line "processId": "${command:pickProcess}".

I would like to automize this flow, triggering it with a simple click on the debug button in VSCode.

launch- and tasks.json

In the above picture I attempt to solve this by running a preLaunchTask before attaching the debugger. This task should host and start the function - which it does so successfully when isolated from the flow. However, when I hit the Debug button with the above configuration, VSCode lets me pick a process immediately before actually having completed the preLaunchTask and so the process func is not yet available.

Is my line of thinking in order? What could I be missing in order for this to work?

Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
Nuss9
  • 425
  • 1
  • 5
  • 12

2 Answers2

5

You might try to create the local Functions app with the Visual Studio Code Functions extension. When you created the Functions app with the extension, it automatically adds a VS Code launch configuration to your project which at least works on my machine :-).

One difference between my and your configuration is the processId which you might change to this: "processId": "${command:azureFunctions.pickProcess}"

Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
  • Or simply remove the .vscode-folder, restart visual code and allow it to re-create those files as they should look like. Those files easily get messed up if you move files around etc. – Henrik May 21 '22 at 20:47
  • They also get easily messed up by just using the Azure Functions extension in VS Code. From experience, it generates broken configurations more often than it creates working ones. I concluded it's not worth it and uninstalled it, creating the configurations manually according to documentation is much faster and more reliable. – Daniel Saner Apr 14 '23 at 13:42
3

The VSCode Function extension works like a charm, the problem is that the team already started on this solution in Visual Studio Windows and so I have to adapt to that.

I did not notice the azureFunctions part in the launch configuration that comes with the extension though! I edited my launch.json to the following:

{
  "name": "Attach to .NET Functions",
  "type": "coreclr",
  "request": "attach",
  "processId": "${command:azureFunctions.pickProcess}"
}

which seemed to do the trick! Notice that there's no preLaunchTask anymore. However, the host gets started, and the debugger gets attached! Thanks @MartinBrandl !

Nuss9
  • 425
  • 1
  • 5
  • 12