Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve some of our recent obsoletions #51721

Merged
merged 5 commits into from
Apr 23, 2021
Merged

Improve some of our recent obsoletions #51721

merged 5 commits into from
Apr 23, 2021

Conversation

jeffhandley
Copy link
Member

I took a pass over all changes since release/net5.0 snapped to find places where we didn't fully align to the new guidance for obsoleting APIs and using SYSLIB0### diagnostic id values; This PR updates those obsoletions to align to the guidance and gets us to a state where all new 6.0 obsoletions are using SYSLIB0### diagnostic ids.

Here are the PRs for which the obsoletions are revised:

I was also able to replace a NET50_OBSOLETIONS build constant with the NET5_0_OR_GREATER constant that the SDK now provides.

To verify that this PR didn't result in any new or removed [Obsolete] attributes, I ran ApiCompat over all libraries comparing the main build to this branch's build. I verified that there were no occurrences of "CannotRemoveAttribute : Attribute 'System.ObsoleteAttribute'" in either comparison direction (after confirming that accidental additions or removals of obsolete attributes would in fact produce a result of that search).

This change will need to be treated as a preview-to-preview breaking change since the obsoletions from #41141 and #50666 would previously require suppressing through the general CS0618 ID and now they have their own diagnostic ids.

@jeffhandley jeffhandley added area-Meta breaking-change Issue or PR that represents a breaking API or functional change over a prerelease. labels Apr 23, 2021
@ghost ghost added the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Apr 23, 2021
@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@AaronRobinsonMSFT
Copy link
Member

LGTM - Thanks!

/cc @jkoritzinsky @elinor-fung

@@ -59,5 +59,11 @@ internal static class Obsoletions

internal const string GetContextInfoMessage = "Use the Graphics.GetContextInfo overloads that accept arguments for better performance and fewer allocations.";
internal const string GetContextInfoDiagId = "SYSLIB0016";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that there's another open PR that adds SYSLIB0017 and SYSLIB0018, which is why I skipped those.

@jeffhandley
Copy link
Member Author

Preview-to-preview breaking change document issue: dotnet/docs#23891

@jeffhandley jeffhandley removed the needs-breaking-change-doc-created Breaking changes need an issue opened with https://github.com/dotnet/docs/issues/new?template=dotnet label Apr 23, 2021
@jeffhandley
Copy link
Member Author

The dotnet/docs#23856 issue is aggregating all breaking change obsoletion documentation.

@stephentoub stephentoub merged commit ac98c81 into dotnet:main Apr 23, 2021
@jeffhandley
Copy link
Member Author

@ericstj / @layomia -- if by chance you have any post-merge feedback, let me know and I'll be happy to address it.

@@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);netcoreapp3.0;netstandard2.0;net461</TargetFrameworks>
<Nullable>enable</Nullable>
<IncludeInternalObsoleteAttribute>true</IncludeInternalObsoleteAttribute>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should a condition be applied here, or instead place one

<When Condition="'$(IncludeInternalObsoleteAttribute)' == 'true' and ($(TargetFramework.StartsWith('netstandard')) or $(TargetFramework.StartsWith('netcoreapp')) or '$(TargetFrameworkIdentifier)' == '.NETFramework')">

so that the attribute isn't included when the framework carries a sufficient copy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As best as I can tell, the condition there in runtime/src/libraries/Directory.Build.targets should already be accomplishing that by only applying for netstandard, netcoreapp, or .NETFramework. I think that would exclude net5.0 and newer.

Is there a condition that I'm missing where you think it could be including the attribute when that's unnecessary? And/or do you think the property should be named such that the condition is connoted?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose you're right. I was thinking of net5.0 as netcoreapp since it's still treated that way behind the scenes, but the way the condition is written it will not apply when folks use net5.0 and we don't use netcoreapp5.0 or netcoreapp6.0 in our repo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I had to go double-check that we used net5.0 and net6.0 (not netcoreapp5.0 / netcoreapp6.0) 😉. We could potentially simplify this down to checking to see if the target framework version is less than 5.0.

Copy link
Member Author

@jeffhandley jeffhandley Apr 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That approach was used just a few lines above actually. I do think it's more concise.

<When Condition="'$(IncludeInternalObsoleteAttribute)' == 'true' and ('$(TargetFrameworkIdentifier)' != '.NETCoreApp' or $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '5.0')))">

This makes me somewhat yearn for the implicitly defined constants of NET5_0_OR_GREATER to also be available as properties. 🤔 But I'll queue up a follow-up PR to make this adjustment. I'll wait a bit though to see if you or @layomia have any other feedback.

Pending branch/PR: https://github.com/dotnet/runtime/compare/main...jeffhandley:jeffhandley/obsoletions-cleanup-followup?expand=1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me somewhat yearn for the implicitly defined constants of NET5_0_OR_GREATER to also be available as properties

Funny: the reason for those constants is that we don't have a complex preprocessor in C#. MSBuild gives you much more flexibility, but there's less prescriptive patterns to follow.

I'm fine so long as we don't unnecessarily duplicate the attribute definition, which was the case already. I like the simplified condition in your diff.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'll leave this as I have it in that pending PR. We'll keep on eye on this to determine if there are enough scenarios to justify MSBuild properties such as NET5_0_OR_GREATER and NET6_0_OR_GREATER.

@jeffhandley jeffhandley deleted the jeffhandley/obsoletions-cleanup branch May 6, 2021 04:28
@karelz karelz added this to the 5.0.x milestone May 20, 2021
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Jun 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Meta breaking-change Issue or PR that represents a breaking API or functional change over a prerelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants