{"record":{"id":"1a5e579c12bdd7fc","repo":"microsoft/aspire","slug":"azureclinotonpathexception-azure-cli-is-not-on-path","errorCode":null,"errorMessage":"AzureCliNotOnPathException (Azure CLI is not on PATH)","messagePattern":"AzureCliNotOnPathException \\(Azure CLI is not on PATH\\)","errorType":"exception","errorClass":"AzureCliNotOnPathException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure/Provisioning/Internal/BicepCompiler.cs","lineNumber":41,"sourceCode":"    public async Task<string> CompileBicepToArmAsync(string bicepFilePath, CancellationToken cancellationToken = default)\n    {\n        // Try bicep command first for better performance\n        var bicepPath = PathLookupHelper.FindFullPathFromPath(\"bicep\");\n        string commandPath;\n        string arguments;\n\n        if (bicepPath is not null)\n        {\n            commandPath = bicepPath;\n            arguments = $\"build \\\"{bicepFilePath}\\\" --stdout\";\n        }\n        else\n        {\n            // Fall back to az bicep if bicep command is not available\n            var azPath = PathLookupHelper.FindFullPathFromPath(\"az\");\n            if (azPath is null)\n            {\n                throw new AzureCliNotOnPathException();\n            }\n            commandPath = azPath;\n            arguments = $\"bicep build --file \\\"{bicepFilePath}\\\" --stdout\";\n        }\n\n        var armTemplateContents = new StringBuilder();\n        var errorContents = new StringBuilder();\n        var templateSpec = new ProcessSpec(commandPath)\n        {\n            Arguments = arguments,\n            OnOutputData = data =>\n            {\n                _logger.LogDebug(\"{CommandPath} (stdout): {Output}\", commandPath, data);\n                armTemplateContents.AppendLine(data);\n            },\n            OnErrorData = data =>\n            {\n                _logger.LogDebug(\"{CommandPath} (stderr): {Error}\", commandPath, data);","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure/Provisioning/Internal/BicepCompiler.cs#L23-L59","documentation":"BicepCompiler.CompileBicepToArmAsync first tries a standalone `bicep` CLI; if absent it falls back to `az bicep build`. If neither is found (PathLookupHelper can't locate `az` on PATH) it throws AzureCliNotOnPathException, indicating the Azure CLI is required to compile the bicep file to ARM.","triggerScenarios":"Provisioning a bicep-based resource on a machine without the Azure CLI (`az`) on PATH and without the standalone Bicep CLI installed — e.g. slim CI containers or fresh dev machines.","commonSituations":"Docker images with only the .NET SDK; CI runners where PATH lacks /usr/bin/az; Azure CLI installed via a non-PATH location; Windows installs where az.exe isn't on the user PATH.","solutions":["Install the Azure CLI (`az`) and ensure it is on PATH (`az --version` works in the same shell that runs the AppHost).","Alternatively install the standalone Bicep CLI (`bicep --version`) so the az fallback is not needed.","In CI, use an image/step that includes the Azure CLI (e.g. Azure/cli@v2 action or microsoft/azure-cli image).","Fix PATH so the install location of az (e.g. ~/.local/bin or /usr/local/bin) is included."],"exampleFix":"// before\n# az: command not found\n// after\ncurl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash && az --version","handlingStrategy":"validation","validationCode":"if (IsWindows)\n    CheckOnPath(\"az.cmd\");\nelse\n    CheckOnPath(\"az\");\n\nstatic void CheckOnPath(string tool)\n{\n    var pathEnv = Environment.GetEnvironmentVariable(\"PATH\") ?? \"\";\n    // simplest precheck: try spawning `<tool> --version` and treat failure as not-installed\n}","typeGuard":null,"tryCatchPattern":"try { await compiler.CompileBicepToArmAsync(bicepPath); }\ncatch (AzureCliNotOnPathException) { /* install Azure CLI or Bicep CLI, fix PATH, retry */ }","preventionTips":["Verify `az --version` (or `bicep --version`) works in the same shell that launches the AppHost.","Use CI images with the Azure CLI preinstalled.","Document CLI prerequisites in the repo README for new contributors."],"tags":["azure","bicep","cli","path","tooling"],"backgroundTag":"command-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}