This article describes how to debug your bot using an integrated development environment (IDE) such as Visual Studio or Visual Studio Code and the Bot Framework Emulator. While you can use these methods to debug any bot locally, this article uses an echo bot, such as the one created in the Create a bot quickstart.
Note
In this article, we use the Bot Framework Emulator to send and receive messages from the bot during debugging. If you are looking for other ways to debug your bot using the Bot Framework Emulator, please read the Debug with the Bot Framework Emulator article.
In Visual Studio Code, you can set breakpoints and run the bot in debug mode to step through your code. To set breakpoints in VS Code, do the following:
Launch VS Code and open your bot project folder.
Set breakpoints as necessary. You can set breakpoints by hovering your mouse over the column to the left of the line numbers. A small red dot will appear. If you click on the dot, the breakpoint is set. If you click the dot again, the breakpoint is removed.
From the menu bar, click Run and then click Start Debugging. Your bot will start running in debugging mode from the Terminal in Visual Studio Code.
From the Emulator, send your bot a message (for example, send the message "Hi"). Execution will stop at the line where you place the breakpoint.
Set C# breakpoints in Visual Studio
In Visual Studio (VS), you can set breakpoints and run the bot in debug mode to step through your code. To set breakpoints in VS, do the following:
Navigate to your bot folder and open the .sln file. This will open the solution in VS.
From the menu bar, click Build and click Build Solution.
In the Solution Explorer, click the .cs file and set breakpoints as necessary. This file defines your main bot logic. In VS, you can set breakpoints by hovering your mouse over the column to the left of the line numbers. A small red dot will appear. If you click on the dot, the breakpoint is set. If you click the dot again, the breakpoint is removed.
From the menu, click Debug and click Start Debugging. At this point, the bot is running locally.
Start the Bot Framework Emulator and connect to your bot as described in the section above.
From the Emulator, send your bot a message, such as "Hi". Execution will stop at the line where you place the breakpoint.
Set JavaScript breakpoints in Visual Studio Code
In Visual Studio Code, you can set breakpoints and run the bot in debug mode to step through your code. To set breakpoints in VS Code, do the following:
Launch VS Code and open your bot project folder.
From the menu bar, click Debug and click Start Debugging. If you are prompted to select a runtime engine to run your code, select Node.js. At this point, the bot is running locally.
Click the .js file and set breakpoints as necessary. In VS Code, you can set breakpoints by hovering your mouse over the column to the left of the line numbers. A small red dot will appear. If you click on the dot, the breakpoint is set. If you click the dot again, the breakpoint is removed.
Install the Java Extension Pack in VS Code, if you have not already done so. This extension provides rich support for Java in VS Code, including debugging.
Launch VS Code and open your bot project folder.
Set breakpoints as necessary. You can set breakpoints by hovering your mouse over the column to the left of the line numbers. A small red dot will appear. If you click on the dot, the breakpoint is set. If you click the dot again, the breakpoint is removed.
Select the EchoBot.java file and add a breakpoint to a desired location.
From the menu bar, click Run and click Start Debugging.
Select Java if prompted to debug the currently selected file.
Install the Python extension in VS Code, if you have not already done so. This extension provides rich support for Python in VS Code, including debugging.
Launch VS Code and open your bot project folder.
Set breakpoints as necessary. You can set breakpoints by hovering your mouse over the column to the left of the line numbers. A small red dot will appear. If you click on the dot, the breakpoint is set. If you click the dot again, the breakpoint is removed.
Select the app.py.
From the menu bar, click Debug and click Start Debugging.
Select Python File to debug the currently selected file.