Migration boilerplate causes "Nullable directive is redundant" if nullable types are disabled
- 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
Assessment
This issue has not been assessed yet.