Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In this quickstart, you build a sample Azure Developer CLI (azd) extension named Contoso Resource Tagger. You use the azd developer extension to scaffold a Go project, add a custom command, and run the extension locally. The sample extension you create is the starting point for the other articles in this section, which show you how to add capabilities, communicate with azd, add a Model Context Protocol (MCP) server, and publish your work.
To learn the concepts behind extension development before you start, see Extension development concepts.
Note
The azd extension framework is generally available. Individual extensions or capabilities might have their own preview status.
Prerequisites
- Install the Azure Developer CLI.
- Install Go 1.26 or later.
- A code editor, such as Visual Studio Code.
azd includes the official extension source by default. You can also install extensions from URL-based or file-based sources, local development registries, opt-in development or nightly registries, and portable .zip bundles. For details, see Extension development concepts.
Tip
If an azd project depends on extension-provided hosts, providers, validation, lifecycle handlers, or commands, declare those required extensions in azure.yaml with version constraints. For details, see requiredVersions.
Install the developer extension
The azd developer extension (microsoft.azd.extensions) provides the azd x commands you use to build extensions.
Install the developer extension from the official extension source:
azd extension install microsoft.azd.extensionsVerify the extension is installed:
azd extension list --installedThe developer extension registers a suite of commands under the
xnamespace. Runazd xto see the available commands.
Scaffold the sample extension
Use the azd x init command to scaffold a new extension project.
Create and change into a directory for your extensions:
mkdir azd-extensions cd azd-extensionsInitialize a git repository and create an initial commit. The
azd x initcommand requires the extension folder to be tracked by git:git init git commit --allow-empty -m "Initial commit"Run the
azd x initcommand to scaffold the extension:azd x initWhen prompted, provide the following values:
Prompt Value Extension ID contoso.azd.taggerDisplay name Contoso Resource TaggerDescription Standardize and report Azure resource tags for an azd project.Namespace taggerCapabilities Custom commandsLanguage Go
The command scaffolds the extension, builds the initial binaries, packages the extension, publishes it to a local extension source, and installs it locally for immediate use.
Explore the project structure
The azd x init command generates a project with the following key files:
contoso.azd.tagger/
├── bin/ # Contains built binaries
├── build.ps1 # Windows build script
├── build.sh # Unix build script
├── CHANGELOG.md # Version history and release notes
├── extension.yaml # Extension metadata and capabilities
├── main.go # Entry point for the extension
├── go.mod # Go module definition
└── internal/ # Internal implementation code
The most important files are:
extension.yaml: Defines the metadata, capabilities, and commands for your extension. To learn more, see Define the extension manifest.main.go: The entry point that runs your extension's root command.build.shandbuild.ps1: Cross-platform build scripts that compile a separate binary for each supported platform (Linux, Windows, and macOS).CHANGELOG.md: Documents changes between versions and provides release notes when you publish.
Add a custom command
Add a show command that prints a greeting to verify your extension works. The exact file layout depends on the starter template, but the pattern is the same: define a Cobra command and register it on the root command.
In the
internal/cmddirectory, create a file namedshow.gowith the following content:package cmd import ( "fmt" "github.com/spf13/cobra" ) func newShowCommand() *cobra.Command { return &cobra.Command{ Use: "show", Short: "Displays a greeting from the Contoso Resource Tagger extension.", RunE: func(cmd *cobra.Command, args []string) error { fmt.Println("Hello from the Contoso Resource Tagger extension!") return nil }, } }Register the command on the root command. In the
internal/cmd/root.gofile, add the following line towards the bottom of the file after the otherAddCommandfunctions:rootCmd.AddCommand(newShowCommand())
Run the extension
Before running the extension, package it and publish it to your local extension source to register your changes.
Package the extension:
azd x packPublish the extension to register it:
azd x publishRun your new command:
azd tagger showThe output resembles the following example:
Hello from the Contoso Resource Tagger extension!
You now have a working extension that you can build on.
Watch for changes during development
Instead of manually running azd x pack and azd x publish after each change, use azd x watch to automatically build and install the extension as you develop.
From the extension directory, start the watcher:
azd x watchIn a second terminal, run your command to test changes as you make them:
azd tagger show
To build the extension manually instead of using the watcher, run azd x build.
Clean up resources
When you finish experimenting, uninstall the sample extension:
azd extension uninstall contoso.azd.tagger
Related content
To continue building on the sample extension, see the following articles. Each article is independent, so you can complete them in any order: