Compiler Warning ASPIRECOMPUTE002
이 콘텐츠는 아직 번역되지 않았습니다.
The
GetHostAddressExpressionmethod is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
This diagnostic warning is reported when using the experimental GetHostAddressExpression method from the IComputeEnvironmentResource interface.
Example
Section titled “Example”The following code generates ASPIRECOMPUTE002:
var builder = DistributedApplication.CreateBuilder(args);
var computeEnv = builder.AddAzureContainerAppEnvironment("env");
// Accessing GetHostAddressExpression on a compute environment resourcevar endpoint = computeEnv.Resource.GetEndpoint("http");var hostAddress = computeEnv.Resource.GetHostAddressExpression(endpoint);Understanding GetHostAddressExpression
Section titled “Understanding GetHostAddressExpression”The GetHostAddressExpression method is part of the IComputeEnvironmentResource interface and provides a way to retrieve the host address or hostname for a specified endpoint reference as a ReferenceExpression.
Key characteristics
Section titled “Key characteristics”- Returns host only — The returned value contains only the hostname or address, without scheme, port, or path information
- Reference expression — Returns a
ReferenceExpressionthat can be evaluated in different contexts - Compute environment specific — Designed for use with compute environment resources like Azure Container Apps, Kubernetes, or Docker Compose
This method is useful when you need to configure resources with just the hostname rather than a full URL, which is common in scenarios like:
- Configuring service-to-service communication within a compute environment
- Setting up DNS-based service discovery
- Configuring load balancers or ingress controllers
To suppress this warning
Section titled “To suppress this warning”Suppress the warning with either of the following methods:
-
Set the severity of the rule in the .editorconfig file.
.editorconfig [*.{cs,vb}]dotnet_diagnostic.ASPIRECOMPUTE002.severity = noneFor more information about editor config files, see Configuration files for code analysis rules.
-
Add the following
PropertyGroupto your project file:C# project file <PropertyGroup><NoWarn>$(NoWarn);ASPIRECOMPUTE002</NoWarn></PropertyGroup> -
Suppress in code with the
#pragma warning disable ASPIRECOMPUTE002directive:C# — Suppressing the warning var builder = DistributedApplication.CreateBuilder(args);var computeEnv = builder.AddAzureContainerAppEnvironment("env");#pragma warning disable ASPIRECOMPUTE002var endpoint = computeEnv.Resource.GetEndpoint("http");var hostAddress = computeEnv.Resource.GetHostAddressExpression(endpoint);#pragma warning restore ASPIRECOMPUTE002
See also
Section titled “See also”- ASPIRECOMPUTE001 — Compute environment resource creation
- ASPIRECOMPUTE003 — Container registry resources