-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fix warnings caused from build attributes for TFM target platforms added by SDK #44231
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @safern, @ViktorHofer |
Why not just disable the logic in the sdk that adds the attributes as a workaround short-term instead of disabling the warning? |
You mean for runtime repo only? That could be the solution for scenario 1, if this could happen only for runtime repo. Also, i think the 2nd warning need more proper handling as it could happen in general |
I reproduced the warnings by removing the section work around: runtime/eng/versioning.targets Lines 168 to 175 in c1b5ac0
Got 679 warnings, 6 of which caused from Scenario 1 mentioned above in the description, Lines 1024 to 1025 in 5d702f8
But for non windows builds assembly level attribute added by MSBuild is causing platform attributes inconsistency and causing the warnings. I don't think we should fix it in the analyzer as it is against the attributes nesting rule and seems only runtime specific issue. My attempts to exclude the API from non windows builds was not successful as it is introducing ApiCompat warning: Type 'System.DirectoryServices.Protocols.QuotaControl' does not exist in the implementation but it does exist in the contract . So i could only use #if-def to exclude windows only API references from other targets builds.
Remaining 673 warnings related to Scenario 2, t first i thought it could happen anywhere, not only runtime, after looking into the warnings closely it is only happening for assemblies having browser target and having shared files with some APIs attributed with <Target Name="RemoveSupportedPlatformAssemblyLevelAttribute" Condition="'$(TargetFrameworkSuffix)' == 'Browser'">
<ItemGroup>
<AssemblyAttribute Remove="System.Runtime.Versioning.SupportedOSPlatformAttribute" />
</ItemGroup>
</Target> |
For the scenario 1, where assembly level attribute added by MSBuild is causing attributes inconsistency with child attributes inside the assembly and overwriting/disabling them could be fixed by changing attributes evaluation order from parent to child into child to parent. This case the parent assembly level attribute is ignored. But for me the rule "Child cannot widen the parent support" implies that the attributes consistency should be evaluated from parent to child as we do it now |
Discussed with @jeffhandley offline, we gonna separate windows specific (scenario 1) and browser unsupported (scenario 2) APIs into separate files so that they are not warning in unrelated builds. Updates for scenario 2 would cover several files from several projects, so i am gonna cover those updates in different PR and for the first round i will keep Supported attribute removed from browser build and fix warning of scenario 1.
|
I was planning to fix browser build warnings by separating all APIs unsupported on the browser, but this issue is still could happen in the future when we add more annotations, which requiring clear separation of platform-specific APIs and forcing developers to duplicate their code to conform to the strict supported-platform name rules. After having some discussions with the mono team and @terrajobst @jeffhandley we decided to fix this issue at the analyzer level. [SupportedOSPlatform("Linux")] // Type only accessible on Linux
public class TestClass
{
[SupportedOSPlatform("windows")] // Having windows only API within Linux only assembly makes this API unreachable
public TestApi()
{
Console.Beep(10, 20); // as this call is unreachable we don't need to warn
}
}
[SupportedOSPlatform("Browser")] // Type only supported on Browser
public class Test
{
private string program;
[UnsupportedOSPlatform("browser")] // Unsupports the only support causing empty callsite
public string CurrentProgram
{
get
{
return program; // as this call is unreachable we don't need to warn
}
}
}
So the tasks list updated to this:
|
Related to the PR
Previously we were stripping the target platforms during build of our csproj. Net5.0 sdk supports the targetPlatformMoniker string for net5.0 and above and hence we no longer need to strip it off for newer frameworks.
With the above change for the builds targeting a specific
platform
MSBuild will be adding assembly-levelSupportedOSPlatform("platform")
which is causing 2 types of CA1416 failures along shared files having some platform-specific annotations, see the failures hereplatform
. When a project has some APIs annotated withSupportedOSPlatform("windows")
but also has a Linux target:net5.0-Linux
MSBuild would produce assembly levelSupportedOSPlatform("Linux")
and simple repro looks like:net5.0-Browser
) because of [UnsupportedOSPlatform("windows")] APIs accessing some fields within the shared file. Example:@Anipik added a rule to remove specified assembly level attributes. #44257
cc @jeffhandley @terrajobst
The text was updated successfully, but these errors were encountered: