Skip to content

For .NET 5 Obsoletions - use partial ref source classes instead of ifdefs #39687

Closed

Description

@jeffhandley

In #39269, we had heavy use of #ifdef statements in the ref source files. This will make the ref source generator harder to re-run for those assemblies.

Instead, we should use sidecar source files and utilize the partial classes to maintain all of the conditional obsoletions. That file can then be conditionally compiled based on the target framework.

Activity

  1. added this to the 5.0.0 milestone on Jul 21, 2020
  2. self-assigned this
    on Jul 21, 2020
  3. added
    untriaged
    on Jul 21, 2020
  4. removed
    untriaged
    on Jul 21, 2020
  5. modified the milestones: 5.0.0, 6.0.0 on Aug 14, 2020
  6. jeffhandley commented on Apr 23, 2021

    @jeffhandley
    MemberAuthor

    Unfortunately, enums and members being marked as conditionally obsolete cannot be handled by partials. (For members, we'd have to mark both sides as partial). That means this approach ends up splitting the conditional obsoletions across the regular ref source file and the partial ref source file. There’s only one ref source file afflicted by this and it’s System.Security.Permissions. I'm not sure this is a good tradeoff since it's not a complete solution.

    I'd love to get the opinion of @bartonjs and (@Anipik or @ViktorHofer) on this. Would this be helpful? I created a draft PR on my fork jeffhandley#5 that shows the (compiling, but unverified) result.

  7. ViktorHofer commented on Apr 23, 2021

    @ViktorHofer
    Member

    We plan to consolidate the ref and source projects hopefully later this year (after product work is completed) and genearte the reference source file automatically when building the project. The idea is to:

    1. Use Roslyn's ReferenceAssembly feature to generate the reference assembly
    2. Use the new ApiCompat tool that @safern is working on to compare the implementation assemblies with the generated reference assembly.
    3. Use another tool (which doesn't exist yet) to generate the reference source file (i.e. System.Runtime.cs) and check it into the source tree next to the project file to make it obvious when APIs change (for PR purposes and to have history on API changes per project). That file isn't required for building the project at all and should be considered as a helper file.

    As the tooling for 3 isn't defined yet I would mimic what we already have with GenAPI: https://github.com/dotnet/arcade/blob/8f38c4b47fa7d6c3cee96df03c3fc1ce2e77d68e/src/Microsoft.DotNet.GenAPI/build/Microsoft.DotNet.GenAPI.targets#L32. How does GenAPI today represent APIs for different TFMs? I assume via ifdefs?

  8. safern commented on Apr 23, 2021

    @safern
    Member

    How does GenAPI today represent APIs for different TFMs? I assume via ifdefs?

    Unfortunately since GenAPI generates source from metadata and it doesn't do a diff in between different TFMs it can't express ifdefs. It basically just generates source based on the settings it get's passed down to.

  9. ViktorHofer commented on Apr 23, 2021

    @ViktorHofer
    Member

    Ah that's not great to hear but if we will invest in new tooling anyway it might not matter much. What would an ideal solution look like? I assume ifdefs would just be fine?

  10. jeffhandley commented on Apr 23, 2021

    @jeffhandley
    MemberAuthor

    Would it be either #ifdef or generate separate source for each target (with no #ifdef logic required then)?

    This upcoming effort makes me feel even less inclined to move this specific issue forward though. Would either of you have any objections to closing this as won't fix?

  11. ViktorHofer commented on Apr 23, 2021

    @ViktorHofer
    Member

    This upcoming effort makes me feel even less inclined to move this specific issue forward though. Would either of you have any objections to closing this as won't fix?

    I agree that based on the automation that we want to implement, this issue might not be useful to invest time on.

  12. ghost locked as resolved and limited conversation to collaborators on May 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions