Skip to content

Fix nullability warnings in projects targeting netstandard2.0 #47179

@captainsafia

Description

@captainsafia

We have MSBuild targets in the repo that enable nullability on netstandard2.0 projects.

<When Condition=" ('$(Nullable)' == 'annotations' OR '$(Nullable)' == 'enable') AND
'$(SuppressNullableAttributesImport)' != 'true' AND
(('$(TargetFrameworkIdentifier)' == '.NETStandard' AND $([MSBuild]::VersionLessThanOrEquals('$(TargetFrameworkVersion)', '2.1'))) OR '$(TargetFrameworkIdentifier)' == '.NETFramework')">
<PropertyGroup>
<DefineConstants>$(DefineConstants),INTERNAL_NULLABLE_ATTRIBUTES</DefineConstants>
<NoWarn>$(NoWarn);nullable</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(SharedSourceRoot)Nullable\NullableAttributes.cs" />
</ItemGroup>
</When>

However, the nullability warnings are not emitted during build by default.

<NoWarn>$(NoWarn);nullable</NoWarn>

Removing the property above shows that we have ~150 unhandled nullability warnings in the projects that currently "enable" nullability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pillar: Technical Debtarea-blazorIncludes: Blazor, Razor Componentsarea-hostingIncludes Hostingarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions