dotnet / dotnet/efcore

Migration boilerplate causes "Nullable directive is redundant" if nullable types are disabled

Open
#31,152 1 comment 0 reactions 0 assignees View on GitHub
area-migrations area-tools customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

## File a bug

Creating a migration includes `#nullable disable` in the generated code. If nullable types are not enabled at the project level, this causes a warning `IDE0240: Nullable directive is redundant` at build time, which in our case fails the build.

### Steps to reproduce

1. Create a csproj with no `Nullable` directive, or `disabled`
2. Add a migration
3. Build the csproj

Expected behaviour: The migration suppresses `#nullable disable` because they are already disabled at the csproj level.

Actual behaviour: The migration includes `#nullable disable`, causing a build warning (and in our case an error in our ADO pipeline).

### Notes

If this will involve reading the state of the `` directive from the csproj, then one approach is [here](https://stackoverflow.com/questions/55392051/how-to-read-csproj-xml-elements-in-runtime).

### Include provider and version information

EF Core version: 7.0.4
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 7.0
Operating system: Windows 10 Enterprise
IDE: Visual Studio 2022 17.6.2

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.