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

Use SupportedOSPlatforms property to generate assembly attributes #41209

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions eng/versioning.targets
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,18 @@
</AssemblyMetadata>
</ItemGroup>

<!-- Adds SupportedOSPlatform attribute for Windows Specific libraries -->
<ItemGroup Condition="'$(IsWindowsSpecific)' == 'true' and '$(IsTestProject)' != 'true'">
<AssemblyAttribute Include="System.Runtime.Versioning.SupportedOSPlatform">
<_Parameter1>windows</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<!-- Adds SupportedOSPlatform or UnsupportedOSPlatform attributes -->
<ItemGroup Condition="'$(IsTestProject)' != 'true'">
<_supportedOSPlatforms Include="$(SupportedOSPlatforms)" />
<_unsupportedOSPlatforms Include="$(UnsupportedOSPlatforms)" />
</ItemGroup>

<Target Name="AddUnsupportedOSPlatformAttribute" BeforeTargets="GenerateAssemblyInfo" AfterTargets="PrepareForBuild">
<Target Name="AddAssemblyOSPlatformAttributes" BeforeTargets="GenerateAssemblyInfo" AfterTargets="PrepareForBuild">
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.Versioning.UnsupportedOSPlatform" Condition="'@(_unsupportedOSPlatforms)' != ''">
<AssemblyAttribute Include="System.Runtime.Versioning.SupportedOSPlatform" Condition="'@(_supportedOSPlatforms)' != ''">
<_Parameter1>%(_supportedOSPlatforms.Identity)</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.Versioning.UnsupportedOSPlatform" Condition="'@(_supportedOSPlatforms)' == '' and '@(_unsupportedOSPlatforms)' != ''">
<_Parameter1>%(_unsupportedOSPlatforms.Identity)</_Parameter1>
</AssemblyAttribute>
Comment on lines +38 to 40
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we produce a build warning when both $(SupportedOSPlatforms) and $(UnsupportedOSPlatforms) are set? Those are mutual exclusive choices, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea

</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@

<!-- Adds System.Runtime.Versioning*Platform* annotation attributes to < .NET 5 builds -->
<Choose>
<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')))">
Copy link
Member

Choose a reason for hiding this comment

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

very good idea to not always require IncludePlatformAttributes when SupportedOSPlatforms or UnsupportedOSPlatforms are used 👍

You could simplify the assemblies annotated in #40612 and replace

    <IncludePlatformAttributes>true</IncludePlatformAttributes>
    <UnsupportedOSPlatforms>browser</UnsupportedOSPlatforms>

with just

    <UnsupportedOSPlatforms>browser</UnsupportedOSPlatforms>

<ItemGroup>
<Compile Include="$(CoreLibSharedDir)System\Runtime\Versioning\PlatformAttributes.cs" Link="System\Runtime\Versioning\PlatformAttributes.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
Copy link
Member

Choose a reason for hiding this comment

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

I thought SupportedOSPlatforms was an Item and not a property?

Copy link
Member Author

@jeffhandley jeffhandley Aug 24, 2020

Choose a reason for hiding this comment

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

There are 2 with similar naming:

  • <SupportedPlatform>, which is an item, and it tells the analyzer which platforms we care to see warnings about, and it's part of the SDK product
  • <SupportedOSPlatforms>, which is this property, and it results in assembly-level [SupportedOSPlatform] attributes, and it's part of the runtime repo only

These names are so similar they're surely easy to get mixed up. Perhaps a better name for the runtime repo properties that produce the assembly-level attributes would be:

  • <AssemblySupportedOSPlatformAttributes>
  • <AssemblyUnsupportedOSPlatformAttributes>

</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Open</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/libraries/System.Data.OleDb/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Open</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Open</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
to a different assembly. -->
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<StrongNameKeyId>ECMA</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
to a different assembly. -->
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/libraries/System.Management/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
to a different assembly. -->
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/libraries/System.Net.Sockets/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
<IncludePlatformAttributes>true</IncludePlatformAttributes>
<UnsupportedOSPlatforms>browser</UnsupportedOSPlatforms>
</PropertyGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Open</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
</PropertyGroup>
</Project>