Skip to content

Commit d3cde47

Browse files
authored
[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.)
1 parent 5b0d78b commit d3cde47

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

Directory.Build.props

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,30 @@
5656
<HumanizerVersion>2.14.1</HumanizerVersion>
5757
<MdocPackageVersion Condition=" '$(MdocPackageVersion)' == '' ">5.9.3</MdocPackageVersion>
5858
</PropertyGroup>
59+
60+
<PropertyGroup>
61+
<!--
62+
Use $(TreatWarningsAsErrors) for CI builds. We have grandfathered some projects that have existing warnings,
63+
but we would like to go ahead and prevent any other projects from getting new warnings.
64+
65+
This can be opted into locally with $(_AndroidTreatWarningsAsErrors) = true.
66+
-->
67+
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'assembly-store-reader.csproj' ">true</_AllowProjectWarnings>
68+
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'decompress-assemblies.csproj' ">true</_AllowProjectWarnings>
69+
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'jnienv-gen.csproj' ">true</_AllowProjectWarnings>
70+
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Microsoft.Android.Sdk.ILLink.csproj' ">true</_AllowProjectWarnings>
71+
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Microsoft.Android.Templates.csproj' ">true</_AllowProjectWarnings>
72+
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Mono.Android.csproj' ">true</_AllowProjectWarnings>
73+
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Mono.Android.NET-Tests.csproj' ">true</_AllowProjectWarnings>
74+
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'MSBuildDeviceIntegration.csproj' ">true</_AllowProjectWarnings>
75+
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'NativeAOT.csproj' ">true</_AllowProjectWarnings>
76+
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'TestRunner.Core.NET.csproj' ">true</_AllowProjectWarnings>
77+
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Xamarin.Android.Build.Tasks.csproj' ">true</_AllowProjectWarnings>
78+
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Xamarin.Android.Build.Tests.csproj' ">true</_AllowProjectWarnings>
79+
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Xamarin.Android.JcwGen-Tests.csproj' ">true</_AllowProjectWarnings>
80+
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Xamarin.Android.NUnitLite.NET.csproj' ">true</_AllowProjectWarnings>
81+
<_AllowProjectWarnings Condition=" '$(MSBuildProjectFile)' == 'Xamarin.ProjectTools.csproj' ">true</_AllowProjectWarnings>
82+
<TreatWarningsAsErrors Condition=" ('$(RunningOnCI)' == 'true' OR '$(_AndroidTreatWarningsAsErrors)' == 'true') AND '$(_AllowProjectWarnings)' != 'true' ">true</TreatWarningsAsErrors>
83+
</PropertyGroup>
5984

6085
</Project>

samples/HelloWorld/HelloLibrary/LibraryActivity.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ protected override void OnCreate(Bundle bundle)
4444

4545
#if __ANDROID_8__
4646
public class MyBackupAgent : BackupAgent {
47-
[Preserve]
4847
public MyBackupAgent ()
4948
{
5049
}

0 commit comments

Comments
 (0)