Build errors coming from RequestDelegateGenerator generated code instead of my code
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
Using the RequestDelegateGenerator in an app that is missing using statements appears to be hiding the real build errors in my code and masking them with build errors from the generated code.
### Expected Behavior
I expect to get a build error in my own code because I am missing the commented out `using` at the top of the C# file.
### Steps To Reproduce
`dotnet build` the following app:
```C#
//using System.Security.Claims;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddAuthentication().AddJwtBearer();
builder.Services.AddAuthorization();
var app = builder.Build();
app.MapGet("/", () => "Hello, World!");
app.MapGet("/secret", (ClaimsPrincipal user) => $"Hello {user.Identity?.Name}. My secret")
.RequireAuthorization();
app.Run();
```
```xml
net8.0
enable
enable
true
true
```
I am only getting errors for generated code:
```
❯ dotnet build
MSBuild version 17.6.0-preview-23174-01+e7de13307 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
C:\dotnet\sdk\8.0.100-preview.4.23179.4\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(287,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [C:\DotNetTest\Net8Web\Net8Web.csproj]
C:\DotNetTest\Net8Web\Microsoft.AspNetCore.Http.RequestDelegateGenerator\Microsoft.AspNetCore.Http.RequestDelegateGenerator.RequestDelegateGenerator\GeneratedRouteBuilderExtensions.g.cs(58,33): error CS0246: The type or namespace name 'ClaimsPrincipal' could not be found (are you missing a using directive or an assembly reference?) [C:\DotNetTest\Net8Web\Net8Web.csproj]
Build FAILED.
C:\DotNetTest\Net8Web\Microsoft.AspNetCore.Http.RequestDelegateGenerator\Microsoft.AspNetCore.Http.equestDelegateGenerator.RequestDelegateGenerator\GeneratedRouteBuilderExtensions.g.cs(58,33): error CS0246: The type or namespace name 'ClaimsPrincipal' could not be found (are you missing a using directive or an assembly reference?) [C:\DotNetTest\Net8Web\Net8Web.csproj]
0 Warning(s)
1 Error(s)
```
### Exceptions (if any)
N/A
### .NET Version
8.0.100-preview.4.23179.4
### Anything else?
N/A
Contributor guide
Assessment
This issue has not been assessed yet.