Aspirerelease/17.0
Watch Aspire live streamsBelgelerAspire'ı deneyin

Compiler Error ASPIREAZURE006

Bu içerik henüz dilinizde mevcut değil.

Version introduced: 17.0

‘Aspire.Hosting.Azure.ManagedIdentityRequiredAnnotation’ is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

The ManagedIdentityRequiredAnnotation annotation marks a compute resource that needs a user-assigned managed identity when you publish to Azure, even when the resource has no Azure role assignments. For example, a resource might need an identity so that a Microsoft Entra ID app registration can trust it.

When Aspire prepares Azure resources for publishing, it creates a user-assigned managed identity for the annotated resource, or reuses one that you added with WithAzureUserAssignedIdentity. After this step, the identity is available from the resource’s AppIdentityAnnotation. Compute environments that don’t support managed identities don’t create one.

This annotation is experimental and might change in future releases. The C# compiler reports ASPIREAZURE006 when your code uses it.

The following code generates ASPIREAZURE006:

AppHost.cs
using Aspire.Hosting.Azure;
var builder = DistributedApplication.CreateBuilder(args);
builder.AddAzureContainerAppEnvironment("env");
// Using ManagedIdentityRequiredAnnotation generates ASPIREAZURE006
builder.AddProject<Projects.Api>("api")
.WithAnnotation(new ManagedIdentityRequiredAnnotation());
builder.Build().Run();

TypeScript AppHosts can’t use this annotation, so they don’t report this diagnostic.

Suppress the error with one of the following methods:

  • Set the severity of the rule in the .editorconfig file.

    .editorconfig
    [*.{cs,vb}]
    dotnet_diagnostic.ASPIREAZURE006.severity = none

    For more information about editor config files, see Configuration files for code analysis rules.

  • Add the following PropertyGroup to your project file:

    C# project file
    <PropertyGroup>
    <NoWarn>$(NoWarn);ASPIREAZURE006</NoWarn>
    </PropertyGroup>
  • Add the following property directive to a file-based AppHost:

    AppHost.cs
    #:property NoWarn=ASPIREAZURE006
  • Suppress in code with the #pragma warning disable ASPIREAZURE006 directive:

    Suppressing the error
    #pragma warning disable ASPIREAZURE006
    builder.AddProject<Projects.Api>("api")
    .WithAnnotation(new ManagedIdentityRequiredAnnotation());
    #pragma warning restore ASPIREAZURE006