Run and debug apps enabled for Azure Developer CLI
Run and debug apps on your local machine using the Visual Studio Code extension for Azure Developer CLI (azd
). In this guide, you'll use the React Web App with Node.js API and MongoDB on Azure template. You can apply the principles you learn in this article to any of the Azure Developer CLI templates.
Prerequisites
Install the Visual Studio Code extension for Azure Developer CLI
Via Visual Studio Code
Open Visual Studio Code.
From the View menu, select Extensions.
In the search field, enter
Azure Developer CLI
.Select Install.
Via Marketplace
Using your browser, go to the Azure Developer CLI - VS Code Extension page.
Select Install.
Initialize a new app
Create and open a new directory in Visual Studio Code.
From the View menu, select Command Palette....
Type and pick
Azure Developer: init
.Select the template
Azure-Samples/todo-nodejs-mongo
.
Explore the following files included in the .vscode
directory:
File | Description |
---|---|
launch.json |
Defines the debug configurations such as Debug Web and Debug API. to see the debug configuration options, select Run from the View menu. The available debug configurations are listed at the top of the pane. To learn more about debugging in Visual Studio Code, see Debugging. |
tasks.json |
Defines the configurations to start the web or API server. To see these configuration options, open the Command Palette and run Task: run task. To learn more about Visual Studio Code Tasks, see Integrate with External Tools via Tasks. |
Note
If you're using the C# SWA-func MS SQL template, you'll need to manually start the Start API task and then Debug API (F5). When asked to pick from a list of running .NET processes, search for the name of your application and select it.
Provision the Azure resources
Before you start debugging, provision the necessary Azure resources.
Open Command Palette.
Enter Azure Developer: provision Azure resources.
Debug an API
The debug configuration Debug API automatically runs the API server and attaches the debugger. To test this pattern, do the following steps:
From your project's
src/api/src/routes
directory, openlists.ts
.Set a breakpoint at line 16.
In the Activity Bar, select Run and Debug > Debug API debug configuration > Start Debugging arrow.
From the View menu, select Debug Console.
Wait for the message indicating the debugger is listening on port 3100.
In your preferred terminal shell, enter the following command:
curl http://localhost:3100/lists
When the breakpoint you set earlier is hit, app execution will pause. At this point, you can perform standard debugging tasks, such as:
- Inspect variables
- Look at the call stack
- Set other breakpoints.
Press
<F5>
to continue running the app. The sample app returns an empty list.
Debug a React Frontend app
To use the Debug Web configuration, you must start both:
- The API server
- The development web server
To test this pattern, do the following steps:
Open the Command Palette and run Task: Run task.
Enter and select Start API and Web
You can check if the local web server is running by navigating to the following URL in a web browser:
http://localhost:3000
.In your project's
src/web/src/components
directory, opentodoItemListPane.tsx
.Set a breakpoint on line 150 (the first line of the
deleteItems
function).In the Activity Bar, select Run and Debug > Debug Web debug configuration > the Start Debugging arrow.
Running the web app will cause your default browser to open the following URL:
http://localhost:3000
. You can now debug the app by adding an item, selecting it from the list, and selecting Delete.When the breakpoint you set earlier is hit, app execution will pause. At this point, you can do standard debugging tasks, such as:
- Inspect variables
- Look at the call stack
- Set other breakpoints
Press
<F5>
to continue running the app and the selected item will be deleted.
Run and debug apps built on your local machine using Visual Studio and Azure Developer CLI (azd
). In this guide, you'll use the React Web App with C# API and MongoDB on Azure template. You can apply the principles you learn in this article to any of the Azure Developer CLI templates.
Prerequisites
Install and enable the preview feature
Install Visual Studio Preview
Note
This is different from Visual Studio. If you have the non-preview version of Visual Studio, you still need to install this.
Open Visual Studio Preview.
From the Tools menu, select Options > Preview Features.
Make sure Integration with azd, the Azure Developer CLI is enabled.
Open the API solution
Open the
Todo.Api.sln
solution in the/src/api
directory.If you've enabled the
azd
integration feature, theazure.yaml
file is detected. Visual Studio automatically initializes the app model and runsazd env refresh
.Expand Connected Services to see all the dependencies.
While the web front-end running on Azure App Service isn't part of the API solution, it's detected and included under Service Dependencies
Run and debug
From your project's
src/api
directory, openListController.cs
.Set a breakpoint at line 20.
Press
<F5>
.Wait for the message indicating the web server is listening on port 3101.
In your preferred browser, enter the following address:
https://localhost:3101/lists
When the breakpoint you set earlier is hit, app execution will pause. At this point, you can perform standard debugging tasks, such as:
- Inspect variables
- Look at the call stack
- Set other breakpoints
Press
<F5>
to continue running the app.The sample app returns a list (or an empty list [] if you haven't launched the web front-end before):
[{"id":"fb9c1cb3811349b993421fc0e815c4c1","name":"My List","description":null,"createdDate":"2022-06-27T01:10:16.7721172+00:00","updatedDate":null}]
Other azd
integrations
Manage azd
environment
To manage the azd
environment:
Select ... in the upper-right corner of the Service Dependencies pane.
Select one of the following options in the dropdown menu:
- Create a new environment
- Select and set a specific environment as the current active environment
- Deprovision an environment
Provision environment resources
You can provision Azure resources to your environment.
In Connected Services, click the icon at the top right to restore/provision environment resources.
Confirm the environment name, subscription, and location.
Publish your app
If you make any updates, you can publish your app by doing the following steps:
In the Solution Explorer, expand Connected Services.
Select Publish.
Select Add a publish profile.
Select a Target of Azure, and select Next.
Select Azure Developer CLI Environment, and select Next.
Select the environment.
Select Finish.
Other resources
Request help
For information on how to file a bug, request help, or propose a new feature for the Azure Developer CLI, please visit the troubleshooting and support page.