dotnet / dotnet/aspnetcore

Should we disable asp0014 when using `WebApplication.CreateEmptyBuilder()`

Open
#50,732 6 comments 0 reactions 0 assignees View on GitHub
analyzer area-minimal
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

Since the empty WebAplicationBuilder would not register routing, maybe we could disable the `ASP0014` using top-level route registrations diagnostic?

We may use the code like below, currently we would get `ASP0014` warning
![image](https://github.com/dotnet/aspnetcore/assets/7604648/43c77567-5609-4531-aa98-95d9ee910e53)

``` c#
var builder = WebApplication.CreateEmptyBuilder(new WebApplicationOptions());
builder.Services.AddRoutingCore();
builder.WebHost.UseKestrelCore();
builder.Logging.AddConsole();

var app = builder.Build();

app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapGet("/", () => "Hello World");
});

app.Run();
```

- https://github.com/dotnet/aspnetcore/pull/49246
- https://learn.microsoft.com/en-us/aspnet/core/diagnostics/asp0014

### Describe the solution you'd like

Ignore it when using the empty `WebApplicationBuilder` since no default global routing

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

No source files or tests are named. Start by reading the ASP0014 documentation and reproducing the warning with the CreateEmptyBuilder example; then locate the analyzer entry point and its tests. Done means the warning is suppressed for the empty builder while remaining for the relevant default routing case.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.