dotnet / dotnet/aspnetcore

Analyzers are tied to `Microsoft.NET.Sdk.Web` making them unavailable in ASP.NET Core library projects

Open
#50,414 3 comments 1 reaction 0 assignees View on GitHub
analyzer area-ui-rendering Pillar: Technical Debt
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

I just went through a trail of issues, starting from this one: #14675

Apparently that was closed due to lack of interest. I don't actually believe there *is* a lack of interest here; I suspect a lot of people just literally aren't *aware* that they aren't getting the analyzers when explicitly referencing the `Microsoft.AspNetCore.App` framework. It took me months to realize that the analyzers were not active in my library project.

The official guidance is to use `Sdk="Microsoft.NET.Sdk"` or `Sdk="Microsoft.NET.Sdk.Razor"`, combined with a `` item, in order to author libraries for ASP.NET Core. Yet if users do so, they get none of the analyzers that come with `Sdk="Microsoft.NET.Sdk.Web"`.

Some docs issues were opened requesting that this behavior at least be documented (https://github.com/dotnet/AspNetCore.Docs/issues/15327, https://github.com/dotnet/AspNetCore.Docs/issues/22879), so clearly people *are* hitting this in the real world. It was finally documented as basically "tough luck" if you're in that exact situation: https://learn.microsoft.com/en-us/aspnet/core/web-api/advanced/analyzers?view=aspnetcore-7.0#analyzers-require-microsoftnetsdkweb

Meanwhile, there was some discussion about improving the situation here: https://github.com/dotnet/sdk/issues/3706

That issue was closed, too, and as far as I can tell, that's where the story unceremoniously ends. But the underlying issue was never resolved, despite the fact that it's a situation where the official guidance on making ASP.NET Core libraries leads to a meaningfully worse developer experience.

So I'm opening this issue in an attempt to get some eyes on this problem again, because it seems like the ball was dropped on this one.

Judging by https://github.com/dotnet/sdk/issues/3706, it *seems* like there's a clear path forward: The web analyzers should be shipped in a similar fashion to how the BCL source generators (STJ, Regex, etc) are shipped today.

Contributor guide

Open the contributing guide

Research direction

Start by reading the issue's linked discussion in dotnet/sdk#3706 and the documented analyzer requirement for Microsoft.NET.Sdk.Web. Investigate how web analyzers are shipped compared with BCL source generators, then verify that ASP.NET Core library projects using Microsoft.NET.Sdk or Microsoft.NET.Sdk.Razor with Microsoft.AspNetCore.App receive the analyzers. Done means the analyzers are available in that supported library setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.