Skip to content

Commit 52d4d8c

Browse files
mark Windows-specific APIs as such (#39265)
* move all OSPlatformAttributes to a single file so they can be easily referenced in < .NET 5 libraries * Adds System.Runtime.Versioning*Platform* annotation attributes to < .NET 5 builds * introduce MinimiumSupportedWindowsPlatform * introduce IsWindowsSpecific setting that adds MinimumOSPlatform attribute for Windows Specific libraries * mark all Windows-specific libraries as such * annotate Windows-specific System.Console methods and properites * annotate Windows-specific DpapiProtectedConfigurationProvider type * annotate throwing Windows-specific APIs from System.Diagnostics.Process namespace * annotate throwing Windows-specific APIs from System.IO.MemoryMappedFiles namespace * annotate Windows-specific APIs from System.IO.Pipes namespace * the new attributes should support enums * annotate Windows-specific APIs from HttpListenerTimeoutManager class * annotate Windows-specific APIs from System.Net.Sockets namespace * annotate Windows-specific APIs from System.Runtime.InteropServices namespace * annotate Windows-specific APIs from System.Security.Cryptography.Csp namespace * annotate Windows-specific APIs from System.Security.Cryptography.X509Certificates namespace * annotate Windows-specific APIs from System.Threading namespace * address code review feedback: dont introduce new constants, reuse existing SYSTEM_PRIVATE_CORELIB * code review: import the namespace, simplify the attribute name * add missing Socket.DuplicateAndClose and Socket(SocketInformation) * fix the test name (it does not throw) * add missing DriveInfo.set_VolumeLabel * add System.IO.FileSystem File Encrypt and Descrypt methods * simplify the < .NET 5 check * enable nullable in explicit way as it's not enabled in all the projects where this file is included * include platform attributes in projects that ask for it in explicit way * set IncludePlatformAttributes to true for projects that include files from other projects * use suggestions from Viktor and Santi Co-authored-by: Viktor Hofer <viktor.hofer@microsoft.com>
1 parent 2a1595e commit 52d4d8c

File tree

101 files changed

+561
-197
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+561
-197
lines changed

eng/Configurations.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<NetCoreAppCurrentBrandName>.NET $(NetCoreAppCurrentVersion)</NetCoreAppCurrentBrandName>
3232

3333
<NetFrameworkCurrent>net472</NetFrameworkCurrent>
34+
<MinimiumSupportedWindowsPlatform>WINDOWS7.0</MinimiumSupportedWindowsPlatform>
3435
</PropertyGroup>
3536

3637
<!-- Honor the generic RuntimeConfiguration property. -->

eng/versioning.targets

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
</AssemblyMetadata>
2323
</ItemGroup>
2424

25+
<!-- Adds MinimumOSPlatform attribute for Windows Specific libraries -->
26+
<ItemGroup Condition="'$(IsWindowsSpecific)' == 'true' and '$(IsTestProject)' != 'true'">
27+
<AssemblyAttribute Include="System.Runtime.Versioning.MinimumOSPlatform">
28+
<_Parameter1>$(MinimiumSupportedWindowsPlatform)</_Parameter1>
29+
</AssemblyAttribute>
30+
</ItemGroup>
31+
2532
<Target Name="DecideIfWeNeedToIncludeDllSafeSearchPathAttribute"
2633
Condition="'$(IsDotNetFrameworkProductAssembly)' == 'true' and '$(IsTestProject)' != 'true' and '$(IsTestSupportProject)' != 'true'">
2734

src/libraries/Directory.Build.targets

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,6 @@
226226
<!-- Adds Nullable annotation attributes to netstandard <= 2.0 builds -->
227227
<Choose>
228228
<When Condition="'$(Nullable)' != '' and ($(TargetFramework.StartsWith('netstandard1')) or '$(TargetFramework)' == 'netstandard2.0' or $(TargetFramework.StartsWith('netcoreapp2')) or '$(TargetFrameworkIdentifier)' == '.NETFramework')">
229-
<PropertyGroup>
230-
<DefineConstants>$(DefineConstants),INTERNAL_NULLABLE_ATTRIBUTES</DefineConstants>
231-
</PropertyGroup>
232229
<ItemGroup>
233230
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\NullableAttributes.cs" Link="System\Diagnostics\CodeAnalysis\NullableAttributes.cs" />
234231
</ItemGroup>
@@ -240,6 +237,15 @@
240237
<ExcludeFromPackage Condition="'$(TargetFramework)' == '$(NetFrameworkCurrent)' and '$(ExcludeCurrentFullFrameworkFromPackage)' == 'true'">true</ExcludeFromPackage>
241238
</PropertyGroup>
242239

240+
<!-- Adds System.Runtime.Versioning*Platform* annotation attributes to < .NET 5 builds -->
241+
<Choose>
242+
<When Condition="('$(IncludePlatformAttributes)' == 'true' or '$(IsWindowsSpecific)' == 'true') and ('$(TargetFrameworkIdentifier)' != '.NETCoreApp' or $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '5.0')))">
243+
<ItemGroup>
244+
<Compile Include="$(CoreLibSharedDir)System\Runtime\Versioning\PlatformAttributes.cs" Link="System\Runtime\Versioning\PlatformAttributes.cs" />
245+
</ItemGroup>
246+
</When>
247+
</Choose>
248+
243249
<!-- The Default behavior in VS is to show files for the first target framework in TargetFrameworks property.
244250
This is required to show all the files corresponding to all target frameworks in VS. -->
245251
<ItemGroup>

src/libraries/Microsoft.IO.Redist/src/Microsoft.IO.Redist.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
<ClsCompliant>false</ClsCompliant>
88
<Nullable>annotations</Nullable>
9+
<IncludePlatformAttributes>true</IncludePlatformAttributes>
910
</PropertyGroup>
1011
<ItemGroup>
1112
<Compile Include="..\..\System.IO.FileSystem\src\System\IO\Directory.cs"

src/libraries/Microsoft.Win32.Registry.AccessControl/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<Import Project="..\Directory.Build.props" />
33
<PropertyGroup>
44
<StrongNameKeyId>Microsoft</StrongNameKeyId>
5+
<IsWindowsSpecific>true</IsWindowsSpecific>
56
</PropertyGroup>
67
</Project>

src/libraries/Microsoft.Win32.Registry/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
<StrongNameKeyId>Microsoft</StrongNameKeyId>
55
<IsNETCoreApp>true</IsNETCoreApp>
66
<IsNETCoreAppRef>false</IsNETCoreAppRef>
7+
<IsWindowsSpecific>true</IsWindowsSpecific>
78
</PropertyGroup>
89
</Project>

src/libraries/Microsoft.Win32.SystemEvents/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<Import Project="..\Directory.Build.props" />
33
<PropertyGroup>
44
<StrongNameKeyId>Open</StrongNameKeyId>
5+
<IsWindowsSpecific>true</IsWindowsSpecific>
56
</PropertyGroup>
67
</Project>

src/libraries/System.Configuration.ConfigurationManager/Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<Import Project="..\Directory.Build.props" />
33
<PropertyGroup>
44
<StrongNameKeyId>Open</StrongNameKeyId>
5+
<IncludePlatformAttributes>true</IncludePlatformAttributes>
56
</PropertyGroup>
67
</Project>

src/libraries/System.Configuration.ConfigurationManager/ref/System.Configuration.ConfigurationManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ public DictionarySectionHandler() { }
607607
protected virtual string ValueAttributeName { get { throw null; } }
608608
public virtual object Create(object parent, object context, System.Xml.XmlNode section) { throw null; }
609609
}
610+
[System.Runtime.Versioning.MinimumOSPlatformAttribute("windows7.0")]
610611
public sealed partial class DpapiProtectedConfigurationProvider : System.Configuration.ProtectedConfigurationProvider
611612
{
612613
public DpapiProtectedConfigurationProvider() { }

src/libraries/System.Configuration.ConfigurationManager/src/System/Configuration/DpapiProtectedConfigurationProvider.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
using System.Security.Cryptography;
66
using System.Text;
77
using System.Xml;
8+
using System.Runtime.Versioning;
89

910
namespace System.Configuration
1011
{
12+
[MinimumOSPlatform("windows7.0")]
1113
public sealed class DpapiProtectedConfigurationProvider : ProtectedConfigurationProvider
1214
{
1315
private bool _useMachineProtection = true;

0 commit comments

Comments
 (0)