CS8618 not ignored for scaffolded DbContext when EnforceCodeStyleInBuild is enabled
- Dominant language
- No language data
- Stars
- 1.9k
- Forks
- 173
- Avg merge
- 10d 13h
- Merged PRs (30d)
- 1
Description
Observation:
When `EnforceCodeStyleInBuild` is enabled, `dotnet format analyzers --verify-no-changes` starts reporting some CS* violations such as **CS8618**/CS8600(nullability) and CS8321(x never used) but it does not report other CS* violations such as CS0029/CS0165(severe) and CS0168/CS0219(x never used). Whether this is by design or not is another story.
Problem:
When EnforceCodeStyleInBuild is enabled, `dotnet format` reports CS8618 even for a `DbSet` inside a `DbContext` which is a special case and is suppressed by `Microsoft.EntityFrameworkCore.Analyzers`.
`dotnet build` and Visual Studio do not report that warning but `dotnet format` does. This breaks my automation scripts.
Tested on .net 7, 8, 9 and 10(rc) - no difference. This is a minimal repro:
Program.cs
```
using MyDbContext db = new();
db.People.Add(new());
```
MyDbContext.cs
```
using Microsoft.EntityFrameworkCore;
class MyDbContext : DbContext { public virtual DbSet People { get; set; } }
public class Person { }
```
Repro.csproj
```
Exe
net9.0
enable
enable
true
```
Output by `dotnet format analyzers --verify-no-changes`:
`warning CS8618: Non-nullable property 'People' must contain a non-null value...`
Partial workaround: Suppress CS8618 also in .editorconfig e.g. with `[*DbContext.cs] dotnet_diagnostic.CS8618.severity = none`
However, this workaround does not work with `WarningsAsErrors` for reasons outside `dotnet format`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.