From d3cde470019a15af433a58a7c8a2e7ebd71e632a Mon Sep 17 00:00:00 2001 From: Jonathan Pobst Date: Mon, 27 Jan 2025 11:58:45 -1000 Subject: [PATCH] [ci] Set `$(TreatWarningsAsErrors)` = `true` for CI builds. (#9689) Modern best practices for software development recommend treating warnings as errors. Although the majority of warnings are benign, warnings for any potential actual issues will be lost in the sea of benign warnings and will not be caught. However, having to fix warnings during the development process can be annoying as code is often in a temporary state. As a balance, we only error on warnings when building on CI. This way local development isn't hindered, but CI will protect us from committing new warnings. Developers can opt-in to the errors locally by setting `$(_AndroidTreatWarningsAsErrors)` to `true`. There are several projects that have warnings today. For now, we will simply grandfather those projects in, allowing us to move forward with protecting the rest of the projects from new warnings. With time, we should endeavor to fix these projects' warnings and remove them from this list. (Our build currently has ~170 warnings spread across these projects.) --- Directory.Build.props | 25 +++++++++++++++++++ .../HelloLibrary/LibraryActivity.cs | 1 - 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 557b0f07777..bf231e2e2de 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -56,5 +56,30 @@ 2.14.1 5.9.3 + + + + <_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'assembly-store-reader.csproj' ">true + <_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'decompress-assemblies.csproj' ">true + <_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'jnienv-gen.csproj' ">true + <_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Microsoft.Android.Sdk.ILLink.csproj' ">true + <_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Microsoft.Android.Templates.csproj' ">true + <_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Mono.Android.csproj' ">true + <_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Mono.Android.NET-Tests.csproj' ">true + <_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'MSBuildDeviceIntegration.csproj' ">true + <_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'NativeAOT.csproj' ">true + <_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'TestRunner.Core.NET.csproj' ">true + <_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Xamarin.Android.Build.Tasks.csproj' ">true + <_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Xamarin.Android.Build.Tests.csproj' ">true + <_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Xamarin.Android.JcwGen-Tests.csproj' ">true + <_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Xamarin.Android.NUnitLite.NET.csproj' ">true + <_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Xamarin.ProjectTools.csproj' ">true + true + diff --git a/samples/HelloWorld/HelloLibrary/LibraryActivity.cs b/samples/HelloWorld/HelloLibrary/LibraryActivity.cs index ffeb017d290..d2d574ee34a 100644 --- a/samples/HelloWorld/HelloLibrary/LibraryActivity.cs +++ b/samples/HelloWorld/HelloLibrary/LibraryActivity.cs @@ -44,7 +44,6 @@ protected override void OnCreate(Bundle bundle) #if __ANDROID_8__ public class MyBackupAgent : BackupAgent { - [Preserve] public MyBackupAgent () { }