diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.cs b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.cs index b51058b9dd..0f35ce425d 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.cs +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.cs @@ -502,6 +502,7 @@ static bool IsKnownValueGuarded( attribute.UnsupportedSecond = null; } attribute.UnsupportedFirst = null; + attribute.UnsupportedMessage = null; } else { @@ -513,6 +514,7 @@ static bool IsKnownValueGuarded( attribute.SupportedSecond = null; attribute.UnsupportedSecond = null; attribute.UnsupportedFirst = null; + attribute.UnsupportedMessage = null; } else if (value.AnalysisValues.Contains(new PlatformMethodValue(info.PlatformName, EmptyVersion, false))) { @@ -530,6 +532,8 @@ static bool IsKnownValueGuarded( attribute.ObsoletedIn.IsGreaterThanOrEqualTo(info.Version)) { attribute.ObsoletedIn = null; + attribute.ObsoletedMessage = null; + attribute.ObsoletedUrl = null; } if (!IsEmptyVersion(info.Version)) @@ -546,6 +550,7 @@ static bool IsKnownValueGuarded( attribute.UnsupportedFirst.IsGreaterThanOrEqualTo(version)) { attribute.UnsupportedFirst = null; + attribute.UnsupportedMessage = null; } if (attribute.UnsupportedSecond != null && @@ -553,6 +558,7 @@ static bool IsKnownValueGuarded( version.IsGreaterThanOrEqualTo(attribute.UnsupportedSecond)) { attribute.UnsupportedSecond = null; + attribute.UnsupportedMessage = null; } } @@ -744,8 +750,11 @@ static void RemoveUnsupportsOnDifferentPlatforms(SmallDictionary attributes, Small platformsBuilder.Add(AppendMessage(pAttribute, GetFormattedString(PlatformCompatibilityFromVersionToVersion, pName, unsupportedVersion, supportedVersion))); } - continue; } - platformsBuilder.Add(AppendMessage(pAttribute, GetFormattedString(PlatformCompatibilityVersionAndLater, pName, supportedVersion))); + else + { + platformsBuilder.Add(AppendMessage(pAttribute, GetFormattedString(PlatformCompatibilityVersionAndLater, pName, supportedVersion))); + } } else { @@ -1018,9 +1033,11 @@ static bool GetPlatformNames(SmallDictionary attributes, Small if (csAttributes != null && HasSameVersionedPlatformSupport(csAttributes, pName, checkSupport: true)) { platformsBuilder.Add(AppendMessage(pAttribute, GetFormattedString(PlatformCompatibilityAllVersions, pName))); - continue; } - platformsBuilder.Add(AppendMessage(pAttribute, EncloseWithQuotes(pName))); + else + { + platformsBuilder.Add(AppendMessage(pAttribute, EncloseWithQuotes(pName))); + } } else { @@ -1578,7 +1595,7 @@ private static bool IsNotSuppressedByCallSite(SmallDictionary } } - // Check if obsoleted attribute suppressed + // Check if obsoleted attribute guarded by callsite attributes if (attribute.ObsoletedIn != null) { if (callSiteAttributes.TryGetValue(platformName, out var callSiteAttribute)) @@ -1811,6 +1828,17 @@ static void MergePlatformAttributes(ImmutableArray immediateAttri existing.SupportedFirst = childAttribute.SupportedFirst; } } + + if (childAttribute.ObsoletedIn != null && + (childAttribute.ObsoletedIn < existing.UnsupportedFirst || + existing.SupportedFirst != null && + (existing.UnsupportedSecond == null || existing.UnsupportedSecond > childAttribute.ObsoletedIn)) && + (existing.ObsoletedIn == null || childAttribute.ObsoletedIn < existing.ObsoletedIn)) + { + existing.ObsoletedIn = childAttribute.ObsoletedIn; + existing.ObsoletedMessage = childAttribute.ObsoletedMessage; + existing.ObsoletedUrl = childAttribute.ObsoletedMessage; + } } else { @@ -1840,10 +1868,12 @@ static void MergePlatformAttributes(ImmutableArray immediateAttri parentAttributes.Callsite = Callsite.Empty; attributes.SupportedFirst = childAttribute.SupportedFirst > attributes.SupportedFirst ? childAttribute.SupportedFirst : null; attributes.UnsupportedFirst = childAttribute.UnsupportedFirst; + attributes.UnsupportedMessage = childAttribute.UnsupportedMessage; } else if (attributes.UnsupportedFirst == null || attributes.UnsupportedFirst > childAttribute.UnsupportedFirst) { attributes.UnsupportedFirst = childAttribute.UnsupportedFirst; + attributes.UnsupportedMessage = childAttribute.UnsupportedMessage; } if (attributes.SupportedSecond.IsGreaterThanOrEqualTo(childAttribute.UnsupportedFirst)) @@ -1853,6 +1883,7 @@ static void MergePlatformAttributes(ImmutableArray immediateAttri if (childAttribute.UnsupportedSecond != null && childAttribute.UnsupportedSecond > attributes.UnsupportedFirst) { attributes.UnsupportedFirst = childAttribute.UnsupportedSecond; + attributes.UnsupportedMessage = childAttribute.UnsupportedMessage; } } } @@ -1862,12 +1893,15 @@ static void MergePlatformAttributes(ImmutableArray immediateAttri notFoundPlatforms.Add(platform); } } + // Check for Obsoleted attributes, only lower version could overwrite - if (attributes.ObsoletedIn != null && - childAttributes.TryGetValue(platform, out var childAttr) && - childAttr.ObsoletedIn != null && childAttr.ObsoletedIn < attributes.ObsoletedIn) + if (childAttributes.TryGetValue(platform, out var childAttr) && + childAttr.ObsoletedIn != null && + (attributes.ObsoletedIn == null || childAttr.ObsoletedIn < attributes.ObsoletedIn)) { attributes.ObsoletedIn = childAttr.ObsoletedIn; + attributes.ObsoletedMessage = childAttr.ObsoletedMessage; + attributes.ObsoletedUrl = childAttr.ObsoletedUrl; } } diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx index 0f91466afe..9fd249e48a 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx @@ -1956,4 +1956,7 @@ This call site is reachable on: {2}. '{0}' is obsoleted on: {1}. This call site is reachable on 'macos', 'linux'. 'OboletedOnMacOS()' is obsoleted on: 'macos'. + + ({0}) + \ No newline at end of file diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.cs.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.cs.xlf index 34b3242234..041cd83a1a 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.cs.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.cs.xlf @@ -1832,6 +1832,11 @@ Metody P/Invoke nemají být viditelné + + ({0}) + ({0}) + + and all other platforms a všechny ostatní platformy diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.de.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.de.xlf index cfce8ad0bb..69ed32acd8 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.de.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.de.xlf @@ -1832,6 +1832,11 @@ P/Invokes dürfen nicht sichtbar sein + + ({0}) + ({0}) + + and all other platforms und alle anderen Plattformen diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.es.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.es.xlf index 3b88decb13..d087e2a755 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.es.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.es.xlf @@ -1832,6 +1832,11 @@ Los elementos P/Invoke no deben estar visibles + + ({0}) + ({0}) + + and all other platforms y el resto de plataformas diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.fr.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.fr.xlf index 74f7bbd7f9..3a20f66f0c 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.fr.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.fr.xlf @@ -1832,6 +1832,11 @@ Les P/Invoke ne doivent pas être visibles + + ({0}) + ({0}) + + and all other platforms et toutes les autres plateformes diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.it.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.it.xlf index fbb23bcf1f..0283857596 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.it.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.it.xlf @@ -1832,6 +1832,11 @@ I metodi P/Invoke non devono essere visibili + + ({0}) + ({0}) + + and all other platforms e tutte le altre piattaforme diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ja.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ja.xlf index 151937e37a..5270c1f896 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ja.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ja.xlf @@ -1832,6 +1832,11 @@ P/Invokes は参照可能にすることはできません + + ({0}) + ({0}) + + and all other platforms およびその他すべてのプラットフォーム diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ko.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ko.xlf index fc29c19491..45035073ea 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ko.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ko.xlf @@ -1832,6 +1832,11 @@ P/Invokes를 표시하지 않아야 합니다. + + ({0}) + ({0}) + + and all other platforms 및 다른 모든 플랫폼 diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pl.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pl.xlf index 36d2d31f4a..b74a8655d8 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pl.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pl.xlf @@ -1832,6 +1832,11 @@ Elementy P/Invoke nie powinny być widoczne + + ({0}) + ({0}) + + and all other platforms i wszystkie inne platformy diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pt-BR.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pt-BR.xlf index 37336f3e62..c799b15293 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pt-BR.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.pt-BR.xlf @@ -1832,6 +1832,11 @@ P/Invokes não deve ser visível + + ({0}) + ({0}) + + and all other platforms e todas as outras plataformas diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ru.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ru.xlf index 78796d070d..9bd1ca7323 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ru.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.ru.xlf @@ -1832,6 +1832,11 @@ Методы P/Invoke не должны быть видимыми + + ({0}) + ({0}) + + and all other platforms и на всех остальных платформах diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.tr.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.tr.xlf index 5df359f2f9..b9ce1103d6 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.tr.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.tr.xlf @@ -1832,6 +1832,11 @@ P/Invokes görünür olmamalıdır + + ({0}) + ({0}) + + and all other platforms ve diğer tüm platformlar diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hans.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hans.xlf index 10d8277e28..287002ea92 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hans.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hans.xlf @@ -1832,6 +1832,11 @@ P/Invokes 应该是不可见的 + + ({0}) + ({0}) + + and all other platforms 和其他所有平台 diff --git a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hant.xlf b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hant.xlf index 144e708b25..f9f174d063 100644 --- a/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hant.xlf +++ b/src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/xlf/MicrosoftNetCoreAnalyzersResources.zh-Hant.xlf @@ -1832,6 +1832,11 @@ 不應看得見 P/Invoke + + ({0}) + ({0}) + + and all other platforms 及所有其他平台 diff --git a/src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.ObsoletedInOSPlatformTests.cs b/src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.ObsoletedInOSPlatformTests.cs index 01f3fe9164..3524147989 100644 --- a/src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.ObsoletedInOSPlatformTests.cs +++ b/src/NetAnalyzers/UnitTests/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.ObsoletedInOSPlatformTests.cs @@ -26,7 +26,7 @@ public class Test [SupportedOSPlatform(""Linux"")] public void M1() { - ObsoletedOnWindows10(); // Shold not warn as only accessible on Linux + ObsoletedOnWindows10(); // Should not warn as only accessible on Linux {|#0:ObsoletedOnLinux4()|}; // This call site is reachable on: 'Linux'. 'Test.ObsoletedOnLinux()' is obsoleted on: 'Linux' 4.1 and later. {|CA1422:ObsoletedOnLinux4AndWindows10()|}; // This call site is reachable on: 'Linux'. 'Test.ObsoletedOnLinux4AndWindows10()' is obsoleted on: 'Linux' 4.1 and later. } @@ -70,7 +70,7 @@ await VerifyAnalyzerVBAsync(vbSource, VerifyVB.Diagnostic(PlatformCompatibilityA } [Fact] - public async Task ObsoletedWithMessageUrlCalledWarns() + public async Task ObsoletedAndSupportedMixedDiagnostics() { var csSource = @" using System; @@ -81,23 +81,113 @@ public class Test { public void CrossPlatform() { - {|#0:ObsoletedWithMessageAndUrl()|}; // This call site is reachable on all platforms. 'Test.ObsoletedWithMessageAndUrl()' is obsoleted on: 'Windows' 10.1.1.1 and later, Use other method instead, http://www/look.for.more.info. - {|#1:ObsoletedWithMessage()|}; // This call site is reachable on all platforms. 'Test.ObsoletedWithMessage()' is obsoleted on: 'Windows' 10.1.1.1 and later, Use other method instead. - ObsoletedOnAndroid(); // Cross platform and android not in the MSBuild list so not warn + {|CA1416:{|CA1422:Supported8Obsoleted10Unsupported11()|}|}; // This call site is reachable on all platforms. 'Test.Supported8Obsoleted10Unsupported11()' is only supported on: 'Windows' from version 8.0 to 11.0. + // This call site is reachable on all platforms. 'Test.Supported8Obsoleted10Unsupported11()' is obsoleted on: 'Windows' 10.0 and later. + {|CA1416:{|CA1422:Supported10.Obsoleted11Unsupported12()|}|}; // This call site is reachable on all platforms. 'Supported10.Obsoleted11Unsupported12()' is only supported on: 'Windows' from version 10.0 to 12.0. + // This call site is reachable on all platforms. 'Supported10.Obsoleted11Unsupported12()' is obsoleted on: 'Windows' 11.0 and later. + {|CA1416:{|CA1422:Supported10.Obsoleted11()|}|}; // This call site is reachable on all platforms. 'Supported10.Obsoleted11()' is only supported on: 'Windows' 10.0 and later. + // This call site is reachable on all platforms. 'Supported10.Obsoleted11()' is obsoleted on: 'Windows' 11.0 and later. + {|CA1416:{|CA1422:Supported10.Unsupported11Obsoleted12()|}|}; // This call site is reachable on all platforms. 'Supported10.Unsupported11Obsoleted12()' is only supported on: 'Windows' from version 10.0 to 11.0. + // This call site is reachable on all platforms. 'Supported10.Unsupported11Obsoleted12()' is obsoleted on: 'Windows' 12.0 and later. + {|CA1416:{|CA1422:Unsupported.Obsoleted1Windows10Linux()|}|}; // This call site is reachable on all platforms. 'Unsupported.Obsoleted1Windows10Linux()' is unsupported on: 'Windows'. + // This call site is reachable on all platforms. 'Unsupported.Obsoleted1Windows10Linux()' is obsoleted on: 'Linux'. + {|CA1416:{|CA1422:UnsupportedSupported8.Obsoleted10()|}|}; // This call site is reachable on all platforms. 'UnsupportedSupported8.Obsoleted10()' is unsupported on: 'Windows' 8.0 and before + // This call site is reachable on all platforms. 'UnsupportedSupported8.Obsoleted10()' is obsoleted on: 'Windows' 10.0 and later. + {|CA1416:{|CA1422:UnsupportedSupported8.Obsoleted10Unspported11()|}|}; // This call site is reachable on all platforms. 'UnsupportedSupported8.Obsoleted10Unspported11()' is unsupported on: 'Windows' 8.0 and before. + // This call site is reachable on all platforms. 'UnsupportedSupported8.Obsoleted10Unspported11()' is obsoleted on: 'Windows' 10.0 and later. + {|CA1416:{|CA1422:UnsupportedSupported8.ObsoletedWindows10Linux()|}|}; // This call site is reachable on all platforms. 'UnsupportedSupported8.ObsoletedWindows10Linux()' is unsupported on: 'Windows' 8.0 and before. + // This call site is reachable on all platforms. 'UnsupportedSupported8.ObsoletedWindows10Linux()' is obsoleted on: 'Linux', 'Windows' 10.0 and later. } - [ObsoletedInOSPlatform(""android21.0"")] - public void ObsoletedOnAndroid() { } + [SupportedOSPlatform(""Windows"")] + public void WindowsOnly() + { + {|CA1416:{|CA1422:Supported8Obsoleted10Unsupported11()|}|}; // This call site is reachable on: 'Windows' all versions. 'Test.Supported8Obsoleted10Unsupported11()' is only supported on: 'Windows' from version 8.0 to 11.0. + // This call site is reachable on: 'Windows' all versions. 'Test.Supported8Obsoleted10Unsupported11()' is obsoleted on: 'Windows' 10.0 and later. + {|CA1416:{|CA1422:Supported10.Obsoleted11Unsupported12()|}|}; // This call site is reachable on: 'Windows' all versions. 'Supported10.Obsoleted11Unsupported12()' is only supported on: 'Windows' from version 10.0 to 12.0. + // This call site is reachable on: 'Windows' all versions. 'Supported10.Obsoleted11Unsupported12()' is obsoleted on: 'Windows' 11.0 and later. + {|CA1416:{|CA1422:Supported10.Obsoleted11()|}|}; // This call site is reachable on: 'Windows' all versions. 'Supported10.Obsoleted11()' is only supported on: 'Windows' 10.0 and later + // This call site is reachable on: 'Windows' all versions. 'Supported10.Obsoleted11()' is obsoleted on: 'Windows' 11.0 and later. + {|CA1416:{|CA1422:Supported10.Unsupported11Obsoleted12()|}|}; // This call site is reachable on: 'Windows' all versions. 'Supported10.Unsupported11Obsoleted12()' is only supported on: 'Windows' from version 10.0 to 11.0. + // This call site is reachable on: 'Windows' all versions. 'Supported10.Unsupported11Obsoleted12()' is obsoleted on: 'Windows' 12.0 and later. + } + + [SupportedOSPlatform(""Windows8.0"")] + [ObsoletedInOSPlatform(""Windows10.0"")] + [Mock.UnsupportedOSPlatform(""Windows11.0"")] + public void Supported8Obsoleted10Unsupported11() { } +} + +[SupportedOSPlatform(""Windows10.0"")] +public class Supported10 +{ + [ObsoletedInOSPlatform(""Windows11.0"")] + [Mock.UnsupportedOSPlatform(""Windows12.0"")] + public static void Obsoleted11Unsupported12() { } + + [ObsoletedInOSPlatform(""Windows11.0"")] + public static void Obsoleted11() { } + + [ObsoletedInOSPlatform(""Windows12.0"")] + [Mock.UnsupportedOSPlatform(""Windows11.0"")] + public static void Unsupported11Obsoleted12() { } +} +[Mock.UnsupportedOSPlatform(""Windows"")] +[SupportedOSPlatform(""Windows8.0"")] +public class UnsupportedSupported8 +{ + [Mock.ObsoletedInOSPlatform(""Windows10.0"")] + public static void Obsoleted10() { } + + [Mock.ObsoletedInOSPlatform(""Linux"")] + [Mock.ObsoletedInOSPlatform(""Windows10.0"")] + public static void ObsoletedWindows10Linux() { } + + [Mock.ObsoletedInOSPlatform(""Windows10.0"")] + [Mock.UnsupportedOSPlatform(""Windows11.0"")] + public static void Obsoleted10Unspported11() { } +} +[Mock.UnsupportedOSPlatform(""Windows"")] +public class Unsupported +{ + [Mock.ObsoletedInOSPlatform(""Linux"")] + [Mock.ObsoletedInOSPlatform(""Windows10.0"")] + public static void Obsoleted1Windows10Linux() { } +} +" + MockObsoletedAttributeCS; + await VerifyAnalyzerCSAsync(csSource, s_msBuildPlatforms); + } + + [Fact] + public async Task ObsoletedWithMessageUrlCalledWarns() + { + var csSource = @" +using System; +using System.Runtime.Versioning; +using Mock; +public class Test +{ + public void CrossPlatform() + { + {|#0:ObsoletedWithMessageAndUrl()|}; // This call site is reachable on all platforms. 'Test.ObsoletedWithMessageAndUrl()' is obsoleted on: 'Windows' 10.1.1.1 and later (Use other method instead http://www/look.for.more.info). + {|#1:ObsoletedWithMessage()|}; // This call site is reachable on all platforms. 'Test.ObsoletedWithMessage()' is obsoleted on: 'Windows' 10.1.1.1 and later (Use other method instead). + {|#2:ObsoletedWithUrl()|}; // This call site is reachable on all platforms. 'Test.ObsoletedWithUrl()' is obsoleted on: 'Windows' 10.1.1.1 and later (http://www/look.for.more.info). + } + + [ObsoletedInOSPlatform(""Windows10.1.1.1"", Url = ""http://www/look.for.more.info"")] + public void ObsoletedWithUrl() { } [ObsoletedInOSPlatform(""Windows10.1.1.1"", ""Use other method instead"", Url = ""http://www/look.for.more.info"")] public void ObsoletedWithMessageAndUrl() { } [ObsoletedInOSPlatform(""Windows10.1.1.1"", ""Use other method instead"")] public void ObsoletedWithMessage() { } }" + MockObsoletedAttributeCS; await VerifyAnalyzerCSAsync(csSource, s_msBuildPlatforms, VerifyCS.Diagnostic(PlatformCompatibilityAnalyzer.ObsoletedCsAllPlatforms).WithLocation(0). - WithArguments("Test.ObsoletedWithMessageAndUrl()", "'Windows' 10.1.1.1 and later, Use other method instead http://www/look.for.more.info"), + WithArguments("Test.ObsoletedWithMessageAndUrl()", "'Windows' 10.1.1.1 and later (Use other method instead http://www/look.for.more.info)"), VerifyCS.Diagnostic(PlatformCompatibilityAnalyzer.ObsoletedCsAllPlatforms).WithLocation(1). - WithArguments("Test.ObsoletedWithMessage()", "'Windows' 10.1.1.1 and later, Use other method instead")); + WithArguments("Test.ObsoletedWithMessage()", "'Windows' 10.1.1.1 and later (Use other method instead)"), + VerifyCS.Diagnostic(PlatformCompatibilityAnalyzer.ObsoletedCsAllPlatforms).WithLocation(2). + WithArguments("Test.ObsoletedWithUrl()", "'Windows' 10.1.1.1 and later (http://www/look.for.more.info)")); } [Fact] @@ -177,8 +267,8 @@ public class Test { public void CrossPlatform() { - [|UnsupportedIosBrowserWatchOS()|]; // This call site is reachable on all platforms. 'Test.UnsupportedIosBrowserWatchOS()' is unsupported on: 'Browser'. Use BrowserSupported() method instead, - // 'ios' 13.0 and later. Use Test.IOsSupported() method instead, 'maccatalyst' 13.0 and later. Use Test.IOsSupported() method instead. + [|UnsupportedIosBrowserWatchOS()|]; // This call site is reachable on all platforms. 'Test.UnsupportedIosBrowserWatchOS()' is unsupported on: 'Browser' (Use BrowserSupported() method instead), + // 'ios' 13.0 and later (Use Test.IOsSupported() method instead), 'maccatalyst' 13.0 and later (Use Test.IOsSupported() method instead). UnsupportedAndroid(); // Cross platform and android not in the MSBuild list so not warn } @@ -186,8 +276,8 @@ public void CrossPlatform() [SupportedOSPlatform(""browser"")] public void ReachableOnAndroidAndBrowser() { - [|UnsupportedIosBrowserWatchOS()|]; // This call site is reachable on: 'Android', 'browser'. 'Test.UnsupportedIosBrowserWatchOS()' is unsupported on: 'Browser', Use BrowserSupported() method instead. - [|UnsupportedAndroid()|]; // This call site is reachable on: 'Android' all versions, 'browser'. 'Test.UnsupportedAndroid()' is unsupported on: 'Android' 21.0 and later, Use other method instead. + [|UnsupportedIosBrowserWatchOS()|]; // This call site is reachable on: 'Android', 'browser'. 'Test.UnsupportedIosBrowserWatchOS()' is unsupported on: 'Browser' (Use BrowserSupported() method instead). + [|UnsupportedAndroid()|]; // This call site is reachable on: 'Android' all versions, 'browser'. 'Test.UnsupportedAndroid()' is unsupported on: 'Android' 21.0 and later (Use other method instead). } [Mock.UnsupportedOSPlatform(""Android21.0"", ""Use other method instead"")] @@ -347,7 +437,7 @@ public void CrossPlatform() { {|CA1422:ObsoletedOnMacOS()|}; // This call site is reachable on all platforms. 'Test.ObsoletedOnMacOS()' is obsoleted on: 'macOS/OSX'. {|CA1422:ObsoletedOnMacOS15()|}; // This call site is reachable on all platforms. 'Test.ObsoletedOnMacOS15()' is obsoleted on: 'macOS/OSX' 15.0 and later. - ObsoletedOnLinuxAndWindows10(); // Guarded with the attirubted API + ObsoletedOnLinuxAndWindows10(); // Guarded with the attrubuted API } }