From d644609b1bd3614529b1fc110fc468c925e8228c Mon Sep 17 00:00:00 2001 From: Jonathan Peppers Date: Wed, 9 Jun 2021 11:32:20 -0500 Subject: [PATCH] [One .NET] set $(EnableSingleFileAnalyzer)=True by default (#5989) Fixes: https://github.com/xamarin/xamarin-android/issues/5943 Context: https://github.com/dotnet/sdk/blob/c1b8e80be1f7cca767ed9f3c90a45d6830b166a0/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Analyzers.targets#L92-L96 Context: https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file Context: https://github.com/dotnet/sdk/pull/15239 [.NET Single File Apps][0] are a .NET deployment construct in which "all application-dependent files [are built] into a single binary." It's conceptually similar to Xamarin.Android `.apk` files, and there is some overlap in the "semantic [API incompatibilities][1]" between "normal" desktop .NET apps and Xamarin.Android/single-file apps, such as the (lack of) utility in `Assembly.Location`, which is the empty string in Xamarin.Android apps when `$(EmbedAssembliesIntoApk)`=True, which is required for "app store" distribution. For .NET 6+ app builds, enable analyzers which check for usage of these "semantically changed" APIs, by setting `$(EnableSingleFileAnalyzer)`=True. Update `Mono.Android.csproj` and `Mono.Android.Export.csproj` to also enable the single-file analyzers. After enabling this analyzer, no warnings appeared. But I do see the appropriate analyzers setup in projects now: Analyzer ~\android-toolchain\dotnet\sdk\6.0.100-preview.6.21280.2\Sdks\Microsoft.NET.Sdk\targets\..\analyzers\ILLink.CodeFixProvider.dll IsImplicitlyDefined = true ~\android-toolchain\dotnet\sdk\6.0.100-preview.6.21280.2\Sdks\Microsoft.NET.Sdk\targets\..\analyzers\ILLink.RoslynAnalyzer.dll IsImplicitlyDefined = true [0]: https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file [1]: https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file#api-incompatibility --- src/Mono.Android.Export/Mono.Android.Export.csproj | 1 + src/Mono.Android/Mono.Android.csproj | 1 + .../targets/Microsoft.Android.Sdk.DefaultProperties.targets | 1 + 3 files changed, 3 insertions(+) diff --git a/src/Mono.Android.Export/Mono.Android.Export.csproj b/src/Mono.Android.Export/Mono.Android.Export.csproj index 83ccc2066c5..6028c5e2105 100644 --- a/src/Mono.Android.Export/Mono.Android.Export.csproj +++ b/src/Mono.Android.Export/Mono.Android.Export.csproj @@ -11,6 +11,7 @@ true false true + true diff --git a/src/Mono.Android/Mono.Android.csproj b/src/Mono.Android/Mono.Android.csproj index e895b336844..877a0665c65 100644 --- a/src/Mono.Android/Mono.Android.csproj +++ b/src/Mono.Android/Mono.Android.csproj @@ -21,6 +21,7 @@ false enable true + true diff --git a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets index 39c2bce7208..969d09519aa 100644 --- a/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets +++ b/src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets @@ -78,6 +78,7 @@ false false true + true false