Azure DevOps Extension Hot Reload and DebugThis repository demonstrates how to load an Azure DevOps extension's code directly from the dev machine rather than bundle all the code and deploy it through the marketplace. We will leverage the (somewhat hidden) capability in Azure DevOps to load content from localhost, which will enable us to use hot reload and debug in VS Code. For more information about our motivation in developing this project, see our blog post. PrerequisitesDownload and install the following tools
Starting a new extensionIf you're starting a new extension, you can either clone this repo or use our Yeoman generator to scaffold a new extension with support for hot reload and debugging. (The following sections provide information about how we configured the template.) Clone
Yeoman
Enabling an existing extensionTo reconfigure your existing extension, follow these steps to get everything working. This configuration assumes you know the basics of how to set up an Azure DevOps extension using Typescript and webpack. For more information, see the Azure DevOps extension docs or the azure-devops-extension-sample repo. Extension manifestThe "trick" to get everything working is to set
We recommend using an overrides JSON file to set this value only for your dev builds. The Create an overrides JSON file with the following content for your dev build called
You can leave default values for these properties in your extension manifest or, for consistency, you can delete them from your manifest and create a
Webpack configYou will need to enable source maps in
By default, webpack serves its compiled, in-memory files directly under
In order to make webpack copy HTML files from the
VS Code's launch.jsonThe last configuration change we need to make is to set up a debug configuration for VS Code that launches Firefox with the correct path mappings. Add a path mapping with
Using hot reload and debuggingNow that you have configured the extension, follow these steps to use hot reload and start debugging your code. Install dependencies and build the extensionBefore we deploy the extension, we need to install its dependencies and compile the code using the following commands:
Deploy your dev extension to Azure DevOpsYou will need to deploy your extension to the marketplace at least once using the following command:
After the extension is published, share it with your Azure DevOps organization and install it. Navigate to a project and you will find a new hub called "Hello World!" When you click it, you will notice that the hub won't load correctly. It isn't loading because the extension is configured to load all its resources (html, images, etc.) from Launch your dev serverStart the webpack-dev-server with:
Now if you go to Go back to Azure DevOps and reload. Your extension should now load correctly and any changes to the source code will cause webpack to recompile and reload the extension automatically. Although most code changes will be reflected immediately, you may still need to occasionally update your extension in the marketplace. The dev extension loads all its resources from the webpack-dev-server, but the manifest itself is being loaded from the published code. Therefore, any changes to the manifest file will not be properly reflected in Azure DevOps until the extension has been republished. Launch your VS Code project to debug against Azure DevOpsIn VS Code, press F5 to start debugging (making sure the webpack-dev-server is still running). The default launch configuration should be set to Launch Firefox. Once Firefox starts up, you will have to go through the steps of allowing the Once you are logged in to Azure DevOps, your extension should be running. Set a breakpoint in a method in VS Code and you should see that breakpoint hit when that method executes.
ConclusionWe hope you enjoy the ability to iterate faster and debug right in VS Code! If you want to start a new extension project, check out the Yeoman generator our team has built to get everything set up faster. Also, if you would prefer to debug your extension in Chrome, please upvote this GitHub issue and add in any relevant comments. ContributingThis project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com. When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments. |