Skip to content

Source generator targets (from NuGet packages) not running on unsupported TFMs #84570

Open

Description

@layomia

The AddNETStandardCompatErrorFileForPackaging target infra to emit a warning for unsupported NuGet package consuming TFMs causes source generator targets (for Roslyn version multitargeting, and for enabling/disabling generators) to get dropped for unsupported TFMs. This is undesirable and can lead to undefined behavior.

PR 9eab1ce fixes this issue for the config binding generator, enforcing that the enabling target runs for all TFMs & also emitting the compat warning for unsupported TFMs. This fix is hardcoded for now. We should also fix it for the other source-generator targets for multi-targeting and disabling, and come up with the right templating across all the targets & packages.

cc @ViktorHofer @ericstj

Activity

  1. added this to the 8.0.0 milestone on Apr 10, 2023
  2. added
    untriaged
    on Apr 13, 2023
  3. removed
    untriaged
    on May 3, 2023
  4. modified the milestones: 8.0.0, Future on May 3, 2023
  5. KalleOlaviNiemitalo commented on Nov 24, 2023

    @KalleOlaviNiemitalo

    The way Microsoft.Extensions.Configuration.Binder checks target framework compatibility in #84379 does not look compatible with target framework aliases. So even if NuGet/Home#5154 is fixed at the NuGet side, aliases still would not work with this package, unless the consuming project sets the SuppressTfmSupportBuildWarnings property.

    I guess fixing that would mean changing

    <_Microsoft_Extensions_Configuration_Binder_Compatible_TargetFramework
    Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netcoreapp2.0')) AND
    !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))"
    >net6.0</_Microsoft_Extensions_Configuration_Binder_Compatible_TargetFramework>
    <_Microsoft_Extensions_Configuration_Binder_Compatible_TargetFramework
    Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net461')) AND
    !$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net462'))"
    >net462</_Microsoft_Extensions_Configuration_Binder_Compatible_TargetFramework>

    to

                <_Microsoft_Extensions_Configuration_Binder_Compatible_TargetFramework
                    Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND
                               $([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '2.0')) AND
                               !$([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '6.0'))"
                    >net6.0</_Microsoft_Extensions_Configuration_Binder_Compatible_TargetFramework>
                <_Microsoft_Extensions_Configuration_Binder_Compatible_TargetFramework
                    Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework' AND
                               $([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '4.6.1')) AND
                               !$([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '4.6.2'))"
                    >net462</_Microsoft_Extensions_Configuration_Binder_Compatible_TargetFramework>

    Fortunately, [MSBuild]::IsTargetFrameworkCompatible is not used in any other packages from dotnet/runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions