diff --git a/Directory.Build.targets b/Directory.Build.targets
index b0bcc3b8c3..187d31b921 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -31,6 +31,7 @@
$(DefineConstants);FEATURE_RANDOM_NEXTINT64_NEXTSINGLE
$(DefineConstants);FEATURE_SPANFORMATTABLE
+ $(DefineConstants);FEATURE_SUPPORTEDOSPLATFORMATTRIBUTE
diff --git a/src/Lucene.Net/Store/NativeFSLockFactory.cs b/src/Lucene.Net/Store/NativeFSLockFactory.cs
index 5935a3ecf7..964bcf3cb1 100644
--- a/src/Lucene.Net/Store/NativeFSLockFactory.cs
+++ b/src/Lucene.Net/Store/NativeFSLockFactory.cs
@@ -4,6 +4,7 @@
using System.IO;
using System.Collections.Generic;
using Lucene.Net.Support.Threading;
+using System.Runtime.Versioning;
namespace Lucene.Net.Store
{
@@ -625,7 +626,7 @@ public override string ToString()
}
// Uses FileStream locking of file pages.
-#if NET6_0
+#if FEATURE_SUPPORTEDOSPLATFORMATTRIBUTE
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
#endif
internal class NativeFSLock : Lock
@@ -832,4 +833,4 @@ public static void Lock(this FileStream stream, long position, long length)
}
}
#endif
-}
\ No newline at end of file
+}