Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/CodeBehind/BuildTests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Android.App;

// This assembly only ever runs on Android (minimum API level 24). Without this
// attribute the platform-compatibility analyzer treats the assembly as platform-neutral
// (because GenerateAssemblyInfo is disabled) and emits spurious CA1416 warnings for every
// call to an [SupportedOSPlatform("android24.0")] API.
[assembly: SupportedOSPlatform ("android24.0")]

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Android.App;

// This test assembly only ever runs on Android (minimum API level 24). Without this
// attribute the platform-compatibility analyzer treats the assembly as platform-neutral
// (because GenerateAssemblyInfo is disabled) and emits spurious CA1416 warnings for every
// call to an [SupportedOSPlatform("android24.0")] API.
[assembly: SupportedOSPlatform ("android24.0")]
Comment on lines +6 to +10

@jonathanpeppers jonathanpeppers Jun 26, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you set the SupportedOSPlatformVersion MSBuild property instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SupportedOSPlatformVersion is actually already set on this project (<SupportedOSPlatformVersion>$(AndroidMinimumDotNetApiLevel)</SupportedOSPlatformVersion>, currently 24) — but it doesn't produce the attribute here.

The .NET SDK only turns SupportedOSPlatformVersion into [assembly: SupportedOSPlatform] inside the GenerateAssemblyInfo target, which is gated on GenerateAssemblyInfo == true (Microsoft.NET.GenerateAssemblyInfo.targets). These test projects set <GenerateAssemblyInfo>false</GenerateAssemblyInfo> to avoid clashing with the hand-written Properties/AssemblyInfo.cs, so the property is inert and no attribute is emitted. The Android SDK consumes SupportedOSPlatformVersion only for typemap/runtime generation, not for the assembly attribute.

So to drive it from the property we'd have to either:

  1. stop setting GenerateAssemblyInfo=false and move everything in Properties/AssemblyInfo.cs (including [assembly: UsesPermission] in TestRunner.Core) into MSBuild, or
  2. add a small target that emits the attribute from $(SupportedOSPlatformVersion) via WriteCodeFragment.

Do you prefer one of those over the explicit [assembly: SupportedOSPlatform]? Happy to wire up (2) if you'd like to keep it property-driven.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, yeah we can remove GenerateAssemblyInfo=false, I remember this problem.

We'd have to migrate attributes to the relevant MSBuild properties -- or you get duplicates.

The MSBuild properties seem better, in general.


// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

Expand Down
7 changes: 7 additions & 0 deletions tests/TestRunner.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Android.App;

// This assembly only ever runs on Android (minimum API level 24). Without this
// attribute the platform-compatibility analyzer treats the assembly as platform-neutral
// (because GenerateAssemblyInfo is disabled) and emits spurious CA1416 warnings for every
// call to an [SupportedOSPlatform("android24.0")] API.
[assembly: SupportedOSPlatform ("android24.0")]

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

Expand Down
Loading