DEV Community

Kenichiro Nakamura
Kenichiro Nakamura

Posted on • Edited on

3

Debug .NET 5 Function with Visual Studio/Visual Studio Code

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
Enter fullscreen mode Exit fullscreen mode

2. Select any trigger as you want. I selected HttpTrigger.
image

3. Run the func for test.

func start
Enter fullscreen mode Exit fullscreen mode

image

4. Call the function for test.

image

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
Enter fullscreen mode Exit fullscreen mode

2. Go to Visual Studio and set break point on Program.cs.

image

3. From Debug menu, click Attach to Process...

image

4. Find dotnet.exe and attach to it. Don't attach to func,exe!

image

5. Now we can do startup debug.

image

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}"
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

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"
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

2. Go to Visual Studio Code and set break point.

image

3. Go to debug menu and click create a launch.json file.

image

4. Select .NET Core.

image

5. From dropdown, select .NET Core Attach.

image

6. Press F5 key and select the dotnet.exe

image

7. Now we can debug it.

image

Enjoy debugging!!

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (3)

Collapse
 
dsschnau profile image
Dan Schnau

Thanks for sharing this, it helped me out today 🙂

Collapse
 
jwisener profile image
Jason Wisener • Edited

Man this lack of coordination between group at ms. Talk about lack of integration/collaboration.

Collapse
 
kenakamu profile image
Kenichiro Nakamura

I really hope we can simply do F5 to debug as soon as possible :)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay