Disable nullable warnings on .NET Standard and Framework (#10677)

Those platforms do not have nullable-annotated BCLs, so things like `Debug.Assert` do not work as expected and cause spurious warnings. This is the same approach that Roslyn takes: https://github.com/dotnet/roslyn/blob/main/eng/targets/Imports.targets#L35-L42.
This commit is contained in:
Fred Silberberg 2024-07-26 15:07:57 -07:00 коммит произвёл GitHub
Родитель 5f0c07a50d
Коммит 6cf62038c2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 15 добавлений и 0 удалений

Просмотреть файл

@ -6,6 +6,21 @@
<PackageVersion Condition=" '$(PackageVersion)' == '' ">$(Version)</PackageVersion>
</PropertyGroup>
<PropertyGroup>
<!--
Disable nullable warnings when targeting anything other than our supported .NET core version(s).
This condition will be evaluated multiple times in multi-targeted projects hence need to be careful
to only set in the inner builds, not the outer build where only $(TargetFrameworks) is defined.
We still check $(TargetFrameworks) for empty though, because for single-targeted builds we want to
allow nullable warnings regardless of target framework.
-->
<DisableNullableWarnings Condition="'$(DisableNullableWarnings)' == '' AND '$(TargetFrameworks)' != '' AND '$(TargetFramework)' != '' AND '$(TargetFrameworkIdentifier)' != '.NETCoreApp'">true</DisableNullableWarnings>
</PropertyGroup>
<PropertyGroup Condition="'$(DisableNullableWarnings)' == 'true'">
<NoWarn>$(NoWarn);Nullable</NoWarn>
</PropertyGroup>
<Import Project="eng\targets\Packaging.targets" />
<!-- Workaround https://github.com/dotnet/cli/issues/10528 -->