-
Notifications
You must be signed in to change notification settings - Fork 467
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
[CA1416] Targeted build attributes can be overriden in cross platform assemblies #5117
[CA1416] Targeted build attributes can be overriden in cross platform assemblies #5117
Conversation
/cc @terrajobst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. And I like this approach much better than the magic string platform name!
Codecov Report
@@ Coverage Diff @@
## release/6.0.1xx #5117 +/- ##
===================================================
+ Coverage 95.57% 95.59% +0.01%
===================================================
Files 1212 1226 +14
Lines 277225 280903 +3678
Branches 16737 16872 +135
===================================================
+ Hits 264971 268528 +3557
- Misses 10020 10096 +76
- Partials 2234 2279 +45 |
...tAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.cs
Outdated
Show resolved
Hide resolved
...tAnalyzers/Core/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzer.cs
Show resolved
Hide resolved
.../UnitTests/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
.../UnitTests/Microsoft.NetCore.Analyzers/InteropServices/PlatformCompatibilityAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
1ab0251
to
77c6a67
Compare
@mavasani @jmarolf I could not understand why the Spanish tests are failing, seems it is not sorting the platform names at all but do not know how could that happen:
|
f43ebbf
to
a4dc1f1
Compare
Fixes #5023
Allow overriding assembly-level attribute in targeted builds of cross-platform assemblies
By the design, child APIs should not extend parent support.
SupportedOSPlatform
attributes illustrate that the API/assembly is only reachable for that platform and it should not have any API supported on other platforms inside it. We have planned to warn if it happens by dotnet/runtime#43971, but this scenario is happening in runtime for targeted cross-platform builds. Ideally, all platform-specific implementation should be separated from cross-platform src. Though that causing code duplication at some level, so most developers would not like to apply strict separation of code.Even though it is an expected scenario by design it is unfortunate to not get any warning about this inconsistency or possible reference of incompatible APIs within the same assembly
Initially, we decided to add a special case
[SupportedOSPlatform("CrossPlatofrm")]
attribute for targeted builds of cross-platform assembly to allow child member attributes to override the parent. For distinguishing real platform-specific assemblies from cross-platform assembly with targeted builds. But usingSupportedOSPlatform
attribute for handling this is causing side effects in further analysis and needs more tweak to get rid of it.So i decided to use MSBuild property
<CompilerVisibleProperty Include="CrossPlatform" />
instead, which we will add into targeted builds of cross platform assembly.(We might change "CrossPlatform" into "PlatformNeutral" or something like that)