跳转到内容

Compiler Warning ASPIRECERTIFICATES001

此内容尚不支持你的语言。

Version introduced: 13.1

Certificate configuration types and members are for evaluation purposes only and are subject to change or removal in future updates. Suppress this diagnostic to proceed.

This diagnostic warning is reported when using experimental certificate configuration APIs in Aspire, including:

  • IDeveloperCertificateService interface
  • HttpsCertificateAnnotation class
  • Certificate-related extension methods like WithHttpsCertificate, WithHttpsDeveloperCertificate, WithoutHttpsCertificate
  • Certificate configuration builder extensions like WithHttpsCertificateConfig and WithHttpsCertificateConfiguration

These APIs enable configuring HTTPS/TLS server certificates for resources in your Aspire application, including support for custom certificates and developer certificates for local development scenarios.

The following code generates ASPIRECERTIFICATES001:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
// Using developer certificate
builder.AddViteApp("frontend")
.WithHttpsDeveloperCertificate();
// Using a custom certificate
var certificate = new X509Certificate2("path/to/certificate.pfx", "password");
builder.AddYarp("gateway")
.WithHttpsCertificate(certificate);
// Disabling HTTPS certificate configuration
builder.AddRedis("cache")
.WithoutHttpsCertificate();
// Using IDeveloperCertificateService
var developerCertService = builder.Services
.BuildServiceProvider()
.GetRequiredService<IDeveloperCertificateService>();

Aspire 13.1 introduced TLS termination support APIs that allow you to configure HTTPS certificates for resources that need to terminate TLS connections. Several containers have built-in TLS termination support:

ContainerDefault
YARPEnabled
RedisEnabled
KeycloakEnabled
Uvicorn (Python)Enabled
Vite (JavaScript)Opt-in

When TLS is enabled by default, the ASP.NET Core developer certificate is automatically used if available and trusted.

The IDeveloperCertificateService provides information about developer certificates:

  • Certificates — List of valid development certificates available for trust
  • SupportsContainerTrust — Indicates if certificates support container domains like host.docker.internal
  • UseForHttps — Indicates if developer certificates should be used for TLS termination by default
  • TrustCertificate — Indicates if certificates should be trusted at runtime by default

Suppress the warning with either of the following methods:

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

    .editorconfig
    [*.{cs,vb}]
    dotnet_diagnostic.ASPIRECERTIFICATES001.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);ASPIRECERTIFICATES001</NoWarn>
    </PropertyGroup>
  • Suppress in code with the #pragma warning disable ASPIRECERTIFICATES001 directive:

    C# — Suppressing the warning
    #pragma warning disable ASPIRECERTIFICATES001
    var developerCertService = builder.Services
    .BuildServiceProvider()
    .GetRequiredService<IDeveloperCertificateService>();
    #pragma warning restore ASPIRECERTIFICATES001
问 & 答协作社区讨论观看