Skip to content

Commit

Permalink
Refactor build to use SupportedOSPlatforms instead of IsWindowsSpecif…
Browse files Browse the repository at this point in the history
…ic (#51450)
  • Loading branch information
jeffhandley authored Apr 20, 2021
1 parent a668de0 commit c7e02f3
Show file tree
Hide file tree
Showing 25 changed files with 50 additions and 42 deletions.
11 changes: 7 additions & 4 deletions eng/targetframeworksuffix.props
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<Project>

<PropertyGroup>
<TargetPlatformSupported>true</TargetPlatformSupported>
<TargetPlatformVersionSupported>true</TargetPlatformVersionSupported>

<!-- Value of 0.0 produces versionless SupportedOSPlatform attribute.
This is required for platforms not expected to have a version,
and we currently omit the version for all platforms. -->
<SupportedOSPlatformVersion>0.0</SupportedOSPlatformVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFrameworkSuffix)' != '' and '$(TargetFrameworkSuffix)' != 'windows'">
<TargetPlatformIdentifier>$(TargetFrameworkSuffix)</TargetPlatformIdentifier>
<TargetPlatformVersion>1.0</TargetPlatformVersion>
<TargetPlatformMoniker>$(TargetFrameworkSuffix),Version=$(TargetPlatformVersion)</TargetPlatformMoniker>
<!-- Value of 0.0 produces versionless SupportedOSPlatform attribute, which is important for platforms not expected to have a version -->
<SupportedOSPlatformVersion>0.0</SupportedOSPlatformVersion>
</PropertyGroup>

<Choose>
<When Condition="'$(TargetFrameworkSuffix)' == 'windows'">
<PropertyGroup>
Expand Down
27 changes: 14 additions & 13 deletions eng/versioning.targets
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@
</AssemblyMetadata>
</ItemGroup>

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

<PropertyGroup Condition="'$(TargetsAnyOS)' == 'true' and !$(TargetFrameworks.Contains('$(TargetFramework)-Browser'))">
<CrossPlatformAndHasNoBrowserTarget>true</CrossPlatformAndHasNoBrowserTarget>
</PropertyGroup>
Expand All @@ -57,29 +50,37 @@
<SupportedPlatform Condition="'$(TargetsUnix)' == 'true'" Include="Unix"/>
</ItemGroup>

<ItemGroup>
<_unsupportedOSPlatforms Include="$(UnsupportedOSPlatforms)" />
<_supportedOSPlatforms Include="$(SupportedOSPlatforms)" />
</ItemGroup>

<!-- Adds UnsupportedOSPlatform and SupportedOSPlatform attributes to the assembly when:
* At least one <UnsupportedOSPlatforms /> or <SupportedOSPlatforms /> has been specified
* This isn't a test project
* This is a cross-platform target
* The build isn't targeting .NET Framework
-->
<Target Name="AddOSPlatformAttributes" BeforeTargets="GenerateAssemblyInfo" AfterTargets="PrepareForBuild"
Condition="'$(TargetsAnyOS)' == 'true' and '$(IsTestProject)' != 'true' and '$(TargetFrameworkIdentifier)' != '.NETFramework'">
<!-- Defensively de-dupe the values -->
<ItemGroup>
<_unsupportedOSPlatforms Include="$(UnsupportedOSPlatforms)" />
<_supportedOSPlatforms Include="$(SupportedOSPlatforms)" />
</ItemGroup>

<ItemGroup Condition="'@(_unsupportedOSPlatforms)' != ''">
<!-- Add the assembly attribute -->
<AssemblyAttribute Include="System.Runtime.Versioning.UnsupportedOSPlatform">
<_Parameter1>%(_unsupportedOSPlatforms.Identity)</_Parameter1>
</AssemblyAttribute>

<!-- Ensure this platform is included in the platforms enabled for the CA1416 analyzer -->
<SupportedPlatform Include="%(_unsupportedOSPlatforms.Identity)" />
</ItemGroup>

<ItemGroup Condition="'@(_supportedOSPlatforms)' != ''">
<!-- Add the assembly attribute -->
<AssemblyAttribute Include="System.Runtime.Versioning.SupportedOSPlatform">
<_Parameter1>%(_supportedOSPlatforms.Identity)</_Parameter1>
</AssemblyAttribute>

<!-- Ensure this platform is included in the platforms enabled for the CA1416 analyzer -->
<SupportedPlatform Include="%(_supportedOSPlatforms.Identity)" />
</ItemGroup>
</Target>

Expand Down
9 changes: 6 additions & 3 deletions src/libraries/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@
<PropertyGroup>
<_ExcludeAPIList>$([MSBuild]::NormalizePath('$(MSBuildProjectDirectory)', '..', 'ref', 'ReferenceSourceExcludeApi.txt'))</_ExcludeAPIList>
<_ExcludeAttributesList>$(RepositoryEngineeringDir)DefaultGenApiDocIds.txt</_ExcludeAttributesList>
<_LicenseHeaderTxtPath>$(RepositoryEngineeringDir)LicenseHeader.txt</_LicenseHeaderTxtPath>
<_LicenseHeaderTxtPath>$(RepositoryEngineeringDir)LicenseHeader.txt</_LicenseHeaderTxtPath>
<GenAPITargetPath>$([MSBuild]::NormalizePath('$(MSBuildProjectDirectory)', '..', 'ref', '$(AssemblyName).cs'))</GenAPITargetPath>
<GenAPIAdditionalParameters>$(GenAPIAdditionalParameters) --exclude-attributes-list "$(_ExcludeAttributesList)"</GenAPIAdditionalParameters>
<GenAPIAdditionalParameters Condition="Exists('$(_ExcludeAPIList)')">$(GenAPIAdditionalParameters) --exclude-api-list "$(_ExcludeAPIList)"</GenAPIAdditionalParameters>
<GenAPIAdditionalParameters>$(GenAPIAdditionalParameters) --header-file "$(_LicenseHeaderTxtPath)"</GenAPIAdditionalParameters>
<GenAPIAdditionalParameters Condition="'$(LangVersion)' != ''">$(GenAPIAdditionalParameters) --lang-version "$(LangVersion)"</GenAPIAdditionalParameters>
<GenAPIAdditionalParameters Condition="'$(LangVersion)' != ''">$(GenAPIAdditionalParameters) --lang-version "$(LangVersion)"</GenAPIAdditionalParameters>
<GenAPIAdditionalParameters Condition="'%(ProjectReference.Identity)' == '$(CoreLibProject)'">$(GenAPIAdditionalParameters) --follow-type-forwards</GenAPIAdditionalParameters>
</PropertyGroup>
</Target>
Expand Down Expand Up @@ -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')))">
<!-- If a project is downlevel from net5.0 but uses the platform support attributes, then we include the classes
in the project as internal. If a project has specified assembly-level SupportedOSPlatforms or UnsupportedOSPlatforms,
we can infer the need without having IncludePlatformAttributes set. -->
<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,7 +2,7 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides support for managing access and audit control lists for Microsoft.Win32.RegistryKey.

Commonly Used Types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsAspNetCoreApp>true</IsAspNetCoreApp>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides support for accessing and modifying the Windows Registry.

Commonly Used Types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Open</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides access to Windows system event notifications.

Commonly Used Types:
Expand Down
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,7 +1,7 @@
<Project>
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides a collection of classes for OLEDB.

Commonly Used Types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<StrongNameKeyId>Open</StrongNameKeyId>
<IsAspNetCoreApp>true</IsAspNetCoreApp>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides the System.Diagnostics.EventLog class, which allows the applications to use the windows event log service.

Commonly Used Types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<Win32Resource>EventLogMessages.res</Win32Resource>
<IncludePlatformAttributes>false</IncludePlatformAttributes>
<!-- Override the parent Directory.Build.props -->
<SupportedOSPlatforms />
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Open</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides the System.Diagnostics.PerformanceCounter class, which allows access to Windows performance counters.

Commonly Used Types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
to a different assembly. -->
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<StrongNameKeyId>ECMA</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides uniform access and manipulation of user, computer, and group security principals across the multiple principal stores: Active Directory Domain Services (AD DS), Active Directory Lightweight Directory Services (AD LDS), and Machine SAM (MSAM).</PackageDescription>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
to a different assembly. -->
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides easy access to Active Directory Domain Services.

Commonly Used Types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides types for managing access and audit control lists for files and directories.

Commonly Used Types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides types for managing access and audit control lists for pipes.

Commonly Used Types:
Expand Down
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,7 +6,7 @@
to a different assembly. -->
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides access to a rich set of management information and management events about the system, devices, and applications instrumented to the Windows Management Instrumentation (WMI) infrastructure.

Commonly Used Types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides a message handler for HttpClient based on the WinHTTP interface of Windows. While similar to HttpClientHandler, it provides developers more granular control over the application's HTTP communication than the HttpClientHandler.

Commonly Used Types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsAspNetCoreApp>true</IsAspNetCoreApp>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides base classes that enable managing access and audit control lists on securable objects.

Commonly Used Types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsAspNetCoreApp>true</IsAspNetCoreApp>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides cryptographic algorithm implementations and key management with Windows Cryptographic Next Generation API (CNG).

Commonly Used Types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides access to Windows Data Protection Api.

Commonly Used Types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsAspNetCoreApp>true</IsAspNetCoreApp>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides classes for retrieving the current Windows user and for interacting with Windows users and groups.

Commonly Used Types:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides the System.ServiceProcess.ServiceContainer class, which allows you to connect to a running or stopped service, manipulate it, or get information about it.

Commonly Used Types:
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/System.Speech/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
to a different assembly. -->
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<StrongNameKeyId>MicrosoftShared</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides types to perform speech synthesis and speech recognition.

Commonly Used Types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Microsoft</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides support for managing access and audit control lists for synchronization primitives.

Commonly Used Types:
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>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Open</StrongNameKeyId>
<IsWindowsSpecific>true</IsWindowsSpecific>
<SupportedOSPlatforms>windows</SupportedOSPlatforms>
<PackageDescription>Provides miscellaneous Windows-specific types

Commonly Used Types:
Expand Down

0 comments on commit c7e02f3

Please sign in to comment.