Skip to main content

Debugging the BotBuilder SDK

Summary

When you install the Bot Builder SDK (.NET) nuget package, the source code is already compiled (into a .dll) and by default, Visual Studio will skip over this code when you try to run it step-by-step using the debugger. The Bot Builder SDK module for NodeJS likewise includes already compiled Typescript.

This quick guide will show you how to setup your Bots such that you can debug the Bot Builder source code for both C# and NodeJS SDKs, letting you see how it all works under the hood.

.NET

C# Prerequisites:

Clone Bot Builder

The Bot Builder is open source with the code available on GitHub

Cloning this repository locally will retrieve the source for both the CSharp and Node Bot Builder SDKs.

C# Project

1) Create a new bot project using the Bot Application template, or open an existing bot project.

2) Open the Nuget Package Manager and uninstall the Microsoft.Bot.Builder package

3) Add the following four projects to your solution. They can be found within the \BotBuilder\CSharp\Library\ folder cloned earlier. Note: the Connector project can be found in the \Library\Microsoft.Bot.Connector.NetFramework folder.

  • Microsoft.Bot.Builder
  • Microsoft.Bot.Builder.Autofac
  • Microsoft.Bot.Connector
  • Microsoft.Bot.Connector.Shared

4) Add project references to .Builder, .Autofac and .Connector into your bot project.

Now when you run the debugger in Visual Studio, you’ll be able to ‘step-in’ to the Bot Builder SDK’s source code and view step-by-step how the internals work.

Node.js

Node Prerequisites:

Note: While you can use any text editor to edit NodeJS applications, we are leveraging VS Code’s debugger

You will need to clone the BotBuilder SDK from the Github repo if you haven’t already. This includes the SDK for both .NET and NodeJS.

You can use one of your own existing bots, clone and use a sample from the BotBuilder-Samples repo, or build your own bot in NodeJS from scratch using the quick start guide.

Following the conventional method, you probably installed the SDK via npm, and the source code for your bot may look something like this.

What we’ll be doing is grabbing the core folder from the cloned Botbuilder/Node folder, and copying it into our application. This is a copy of the BotBuilder SDK that you would normally install as an npm module.

Next, all we need to do is comment out the path to the botbuilder npm module, then replace it with a new builder using relative path to the core folder. After that, don’t forget to verify that the necessary modules from the core folder are installed, you’ll notice that there is also a package.json file in there as well. You can npm-install in the core folder to install/verify any missing dependencies.

And that’s it! We’ve shown you a simple way to allow for debugging the Bot Builder SDK for both .NET and NodeJS so that you can take a look at what’s going on under the hood.

We’d also like to encourage you to contribute to the Bot Bot Builder source code directly. The Bot Builder is part of the Microsoft Open Source Code of Conduct, as well as many other projects in the Bot Framework.

Happy Making!

Eric Dahlvang and Matthew Shim from the Bot Framework Team