From 1e6bd9ec9f3864f16aa872fd461760204821b4ae Mon Sep 17 00:00:00 2001 From: Simon Rozsival Date: Sun, 28 Jun 2026 18:52:59 +0200 Subject: [PATCH] [tests] Fix CA1416 by enabling SupportedOSPlatform via MSBuild Android-targeted test projects emitted ~1300 CA1416 warnings per build (e.g. in Mono.Android.NET-Tests) because they set false to avoid clashing with hand-written Properties/AssemblyInfo.cs. With assembly-info generation disabled, the .NET SDK never emits the [assembly: SupportedOSPlatform("android24.0")] attribute that it normally derives from , so the platform-compatibility analyzer treats these assemblies as platform-neutral and flags every call to a Mono.Android API. Remove false so the SDK emits the platform attribute from the existing property (default android24.0), and delete the hand-written Properties/AssemblyInfo.cs files to avoid duplicate attribute errors. The cosmetic assembly metadata they declared is not needed on test assemblies and is dropped; the only functional attribute, TestRunner.Core's [assembly: UsesPermission(...READ_PHONE_STATE)], is preserved as an item. This fixes the warnings at their root rather than suppressing CA1416. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../CodeBehindBuildTests.NET.csproj | 2 -- .../BuildTests/Properties/AssemblyInfo.cs | 27 ----------------- .../Mono.Android.NET-Tests.csproj | 9 ++---- .../Properties/AssemblyInfo.cs | 28 ----------------- .../Properties/AssemblyInfo.cs | 30 ------------------- .../TestRunner.Core.NET.csproj | 8 ++++- 6 files changed, 10 insertions(+), 94 deletions(-) delete mode 100644 tests/CodeBehind/BuildTests/Properties/AssemblyInfo.cs delete mode 100644 tests/Mono.Android-Tests/Mono.Android-Tests/Properties/AssemblyInfo.cs delete mode 100644 tests/TestRunner.Core/Properties/AssemblyInfo.cs diff --git a/tests/CodeBehind/BuildTests/CodeBehindBuildTests.NET.csproj b/tests/CodeBehind/BuildTests/CodeBehindBuildTests.NET.csproj index 25439f6fff7..c37e8660db7 100644 --- a/tests/CodeBehind/BuildTests/CodeBehindBuildTests.NET.csproj +++ b/tests/CodeBehind/BuildTests/CodeBehindBuildTests.NET.csproj @@ -6,7 +6,6 @@ True <_ApkDebugKeyStore>debug.keystore false - false Resources\Resource.designer.cs false false @@ -34,7 +33,6 @@ - diff --git a/tests/CodeBehind/BuildTests/Properties/AssemblyInfo.cs b/tests/CodeBehind/BuildTests/Properties/AssemblyInfo.cs deleted file mode 100644 index 9c50308b3c6..00000000000 --- a/tests/CodeBehind/BuildTests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using Android.App; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle ("code_behind_few")] -[assembly: AssemblyDescription ("")] -[assembly: AssemblyConfiguration ("")] -[assembly: AssemblyCompany ("")] -[assembly: AssemblyProduct ("")] -[assembly: AssemblyCopyright ("Marek Habersack")] -[assembly: AssemblyTrademark ("")] -[assembly: AssemblyCulture ("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion ("1.0.0")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] diff --git a/tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj b/tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj index bf233d38d9c..aa9cc083cb0 100644 --- a/tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj +++ b/tests/Mono.Android-Tests/Mono.Android-Tests/Mono.Android.NET-Tests.csproj @@ -12,7 +12,6 @@ <_SkipJniAddNativeMethodRegistrationAttributeScan>True true $(XamarinAndroidSourcePath)bin\Test$(Configuration) - false false false false @@ -31,10 +30,9 @@ `AppContext.GetData` / `AppContext.TryGetSwitch`. See `TestInstrumentation.ExcludedCategories` / `TestInstrumentation.IncludedCategories`. - `` is preferred over `` here - because `false` (set above to avoid - clashing with `Properties/AssemblyInfo.cs`) silently suppresses - `` items. + `` is used (rather than ``) + because these values must be emitted into runtimeconfig.json so the on-device + instrumentation can read them at runtime via `AppContext`. --> @@ -123,7 +121,6 @@ - diff --git a/tests/Mono.Android-Tests/Mono.Android-Tests/Properties/AssemblyInfo.cs b/tests/Mono.Android-Tests/Mono.Android-Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index dbb0cde4889..00000000000 --- a/tests/Mono.Android-Tests/Mono.Android-Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using Android.App; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle("runtime")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Xamarin Inc.")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("Xamarin Inc.")] -[assembly: AssemblyTrademark("Xamarin")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion("1.0.0")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] - diff --git a/tests/TestRunner.Core/Properties/AssemblyInfo.cs b/tests/TestRunner.Core/Properties/AssemblyInfo.cs deleted file mode 100644 index f03603e4cd2..00000000000 --- a/tests/TestRunner.Core/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using Android.App; - -// Information about this assembly is defined by the following attributes. -// Change them to the values specific to your project. - -[assembly: AssemblyTitle("TestRunner.Core")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("Microsoft, Inc")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". -// The form "{Major}.{Minor}.*" will automatically update the build and revision, -// and "{Major}.{Minor}.{Build}.*" will update just the revision. - -[assembly: AssemblyVersion("1.0.0")] - -// The following attributes are used to specify the signing key for the assembly, -// if desired. See the Mono documentation for more information about signing. - -//[assembly: AssemblyDelaySign(false)] -//[assembly: AssemblyKeyFile("")] - -// Needed to read the device serial number -[assembly: UsesPermission (Name = Android.Manifest.Permission.ReadPhoneState)] diff --git a/tests/TestRunner.Core/TestRunner.Core.NET.csproj b/tests/TestRunner.Core/TestRunner.Core.NET.csproj index a5bcfb3efa9..a2090bd5d1b 100644 --- a/tests/TestRunner.Core/TestRunner.Core.NET.csproj +++ b/tests/TestRunner.Core/TestRunner.Core.NET.csproj @@ -7,11 +7,17 @@ $(AndroidMinimumDotNetApiLevel) Library Xamarin.Android.UnitTests - false enable enable + + + + android.permission.READ_PHONE_STATE + + +