-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Improve some of our recent obsoletions #51721
Conversation
Note regarding the 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. |
LGTM - Thanks! |
@@ -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"; | |||
|
There was a problem hiding this comment.
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.
Preview-to-preview breaking change document issue: dotnet/docs#23891 |
The dotnet/docs#23856 issue is aggregating all breaking change obsoletion documentation. |
@@ -2,6 +2,7 @@ | |||
<PropertyGroup> | |||
<TargetFrameworks>$(NetCoreAppCurrent);netcoreapp3.0;netstandard2.0;net461</TargetFrameworks> | |||
<Nullable>enable</Nullable> | |||
<IncludeInternalObsoleteAttribute>true</IncludeInternalObsoleteAttribute> |
There was a problem hiding this comment.
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
runtime/src/libraries/Directory.Build.targets
Line 247 in 466deef
<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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
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 usingSYSLIB0###
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 usingSYSLIB0###
diagnostic ids.Here are the PRs for which the obsoletions are revised:
I was also able to replace a
NET50_OBSOLETIONS
build constant with theNET5_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 ranApiCompat
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.