AspNetCore.Docs/aspnetcore/diagnostics/asp0013.md

56 lines
1.5 KiB
Markdown

---
title: "ASP0013: Suggest switching from using Configure methods to WebApplicationBuilder.Configuration"
description: "Learn about analysis rule ASP0013: Suggest switching from using Configure methods to WebApplicationBuilder.Configuration"
author: safia
monikerRange: '>= aspnetcore-7.0'
ms.author: safia
ms.date: 09/27/2022
uid: diagnostics/asp0013
---
# ASP0013: Suggest switching from using Configure methods to WebApplicationBuilder.Configuration
| | Value |
|-|-|
| **Rule ID** |ASP0013|
| **Category** |Usage|
| **Fix is breaking or non-breaking** |Non-breaking|
## Cause
`Configure` isn't the recommended strategy for reading and writing to configuration in a minimal API application.
## Rule description
`Configure` isn't the recommended strategy for configuring logging in a minimal API application.
```csharp
var builder = WebApplication.CreateBuilder(args);
builder.Host.ConfigureAppConfiguration(builder =>
{
builder.AddJsonFile("customAppSettings.json");
})
var app = builder.Build();
app.Run();
```
## How to fix violations
To fix a violation of this rule, use the `Configuration` property on the `WebApplicationBuilder` to modify application configuration directly without the need for an additional `ConfigureAppConfiguration` call.
```csharp
var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddJsonFile("customAppSettings.json");
var app = builder.Build();
app.Run();
```
## When to suppress warnings
Do ***not*** suppress a warning from this rule.