File: FuncCoreToolsInstallationManager.cs
Web Access
Project: src\src\Aspire.Hosting.Azure.Functions\Aspire.Hosting.Azure.Functions.csproj (Aspire.Hosting.Azure.Functions)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
 
using Aspire.Hosting.Utils;
using Microsoft.Extensions.Logging;
 
namespace Aspire.Hosting.Azure;
 
/// <summary>
/// Validates that the Azure Functions Core Tools (func) command is available on the system.
/// </summary>
#pragma warning disable ASPIREINTERACTION001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
internal sealed class FuncCoreToolsInstallationManager : RequiredCommandValidator
{
    public FuncCoreToolsInstallationManager(
        IInteractionService interactionService,
        ILogger<FuncCoreToolsInstallationManager> logger)
        : base(interactionService, logger)
    {
    }
 
    /// <summary>
    /// Ensures Azure Functions Core Tools are installed/available. This method is safe for concurrent callers;
    /// only one validation will run at a time.
    /// </summary>
    /// <param name="throwOnFailure">Whether to throw an exception if func is not found. Default is true.</param>
    /// <param name="cancellationToken">Cancellation token.</param>
    public Task EnsureInstalledAsync(bool throwOnFailure = true, CancellationToken cancellationToken = default)
    {
        SetThrowOnFailure(throwOnFailure);
        return RunAsync(cancellationToken);
    }
 
    protected override string GetCommandPath() => "func";
 
    protected override string? GetHelpLink() => "https://learn.microsoft.com/azure/azure-functions/functions-run-local#install-the-azure-functions-core-tools";
}
#pragma warning restore ASPIREINTERACTION001