As we start developing Azure Function with .NET 5, we start wondering how to properly debug the application. Even though we cannot start with F5 as usual, func cli provides --dotnet-isolated-debug option.
Create Simple Function
1. Create a folder and create new Function with dotnet-isolated runtime.
mkdir debugmyfunction
cd debugmyfunction
func new -n debugtest --worker-runtime dotnet-isolated
2. Select any trigger as you want. I selected HttpTrigger.
3. Run the func for test.
func start
4. Call the function for test.
Debug the startup with Visual Studio
We can attach to the process after
func start
, however if we want to debug startup logic, then we can do like this.
1. Run the func by adding --dotnet-isolated-debug option.
func start --dotnet-isolated-debug
2. Go to Visual Studio and set break point on Program.cs.
3. From Debug menu, click Attach to Process...
4. Find dotnet.exe and attach to it. Don't attach to func,exe!
5. Now we can do startup debug.
Debug the startup with Visual Studio Code
We can do F5 with Visual Studio Code or use same process as Visual Studio.
Use F5
To make F5 debug works, we simply need launch.json in .vscode folder. If you need to debug the startup, you need tasks.json as well to specify --dotnet-isolated-debug
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to .NET Functions",
"type": "coreclr",
"request": "attach",
"processId": "${command:azureFunctions.pickProcess}"
}
]
}
tasks.json
Optional.
{
"version": "2.0.0",
"tasks": [
{
"type": "func",
"options": {
"cwd": "${workspaceFolder}/bin/Debug/net5.0"
},
"command": "host start --dotnet-isolated-debug",
"isBackground": true,
"problemMatcher": "$func-dotnet-watch"
}
]
}
Use --dotnet-isolated-debug
We can do the same as Visual Studio, too.
1. Run the func by adding --dotnet-isolated-debug option.
func start --dotnet-isolated-debug
2. Go to Visual Studio Code and set break point.
3. Go to debug menu and click create a launch.json file.
4. Select .NET Core.
5. From dropdown, select .NET Core Attach.
6. Press F5 key and select the dotnet.exe
7. Now we can debug it.
Enjoy debugging!!
Top comments (3)
Thanks for sharing this, it helped me out today π
Man this lack of coordination between group at ms. Talk about lack of integration/collaboration.
I really hope we can simply do F5 to debug as soon as possible :)