-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Refactor the platform support attribute generation in the build #51450
Refactor the platform support attribute generation in the build #51450
Conversation
Tagging subscribers to this area: @Anipik, @safern, @ViktorHofer Issue DetailsRefactor the With #49261, we resurrected the idea of having an MSBuild property for Here are some concepts important to note:
In this PR, the logic for our build is refactored to:
Testing the refactor and evaluating our attribute production consistency was annoying, so I crafted a utility that can scan the The net effects are:
|
@jeffhandley excellent summary of the current state and what's being changed by this PR 👍 |
Would there be value in moving these properties into the SDK in case other products want or need to do something similar? |
Thanks, @ViktorHofer! I do think we'll eventually want the SDK to have built-in support for using properties/items to produce the attributes. I don't think what we have here is quite ready for baking in though. I'd like to see us work through the remaining 6.0 work of annotating libraries for the new platforms so we can see if any other scenarios surface that we'd need to account for. I also think moving to an |
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.
LGTM, thanks!
@@ -232,7 +232,10 @@ | |||
<!-- Adds System.Runtime.Versioning*Platform* annotation attributes to < .NET 5 builds --> | |||
<Choose> | |||
<When Condition="'$(IncludePlatformAttributes)' == 'false'" /> | |||
<When Condition="('$(IncludePlatformAttributes)' == 'true' or '$(IsWindowsSpecific)' == 'true') and ('$(TargetFrameworkIdentifier)' != '.NETCoreApp' or $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '5.0')))"> | |||
<When Condition="('$(IncludePlatformAttributes)' == 'true' or '$(SupportedOSPlatforms)' != '' or '$(UnsupportedOSPlatforms)' != '') and ('$(TargetFrameworkIdentifier)' != '.NETCoreApp' or $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '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.
Nit: a simpler way to do this would've been setting IncludePlatformAttributes
to true if it was empty and any of SupportedOSPlatforms
or UnsupportedOSPlatforms
is not empty.
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.
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.
Yeah exactly... that simplifies this hard to read condition.
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. PR incoming.
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.
LGTM
Refactor the
SupportedOSPlatform
/UnsupportedOSPlatform
attribute generation in the build to make it more consistent with fewer moving parts.With #49261, we resurrected the idea of having an MSBuild property for
<SupportedOSPlatforms>
which was entertained in #41209 but not merged. This is a follow-up PR that further utilizes that new property and simplifies the logic overall while improving consistency of the attributes across the configurations.Here are some concepts important to note:
[SupportedOSPlatform]
attributes for recognized platforms, such asnet6.0-windows
andnet6.0-ios
<SupportedOSPlatformVersion>
as a property to override the version number it uses on the attributes, with0.0
meaning to omit the version<SupportedPlatform>
item to get the list of platform names the build recognizesios
) are not included by defaultSolaris
net6.0
) need to have assembly-level[SupportedOSPlatform]
and[UnsupportedOSPlatform]
attributes to indicate library-wide support<SupportedOSPlatforms>
and<UnsupportedOSPlatforms>
properties to achieve thatSupportedOSPlatformAttribute
andUnsupportedOSPlatformAttribute
types were introduced in net5.0, but we have places where we annotate libraries/APIs with the attributes innetstandard
builds<IncludePlatformAttributes>true</IncludePlatformAttributes>
property that can be specified to include those types (as internal) in the projectIn this PR, the logic for our build is refactored to:
<IsWindowsSpecific>true</IsWindowsSpecific>
property that was introduced in mark Windows-specific APIs as such #39265 with<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<SupportedOSPlatformVersion>0.0</SupportedOSPlatformVersion>
to produce versionless attributesWindows7.0
attributeswindows
platform name without a versionwindows
and some that wereWindows7.0
; we even had some getting both<SupportedOSPlatforms>
or<UnsupportedOSPlatforms>
, we now explicitly add the platform to<SupportedPlatform>
to ensure it's a recognized platform name (for custom targets not recognized by the SDK)<IncludePlatformAttributes>true</IncludePlatformAttributes>
when any<SupportedOSPlatform>
or ` value exists and the target is downlevel from net5.0Testing the refactor and evaluating our attribute production consistency was annoying, so I crafted a utility that can scan the
artifacts
folder and build a report of all libraries' generated attributes. This utility looks in the generatedAssemblyInfo.cs
files for each library and reports on thesrc
andref
builds' attributes forSupportedOSPlatform
andUnsupportedOSPlatform
. I produced a copy of that report frommain
before this PR and then produced a copy of that report from after PR's changes.The net effects are:
[SupportedOSPlatform("Windows7.0")]
produced; those are now[SupportedOSPlatform("windows")]
to be consistent throughout"Windows7.0"
and"windows"
produced; this is now reduced to just"Windows"
(side effect of the above change)netstandard
platform-specific builds were getting the attributes produced, but that wasn't intentional (only the cross-platform build was intended to have them)[SupportedOSPlatform]
attribute applied by the SDK itself[SupportedOSPlatform("Windows")]
and[UnsupportedOSPlatform("browser")]
, which is not desired. The result should just be[UnsupportedOSPlatform("browser")]