-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LayoutBindings: 'PreserveAttribute' is obsolete warnings #7480
Comments
Those look like they are coming from the See https://learn.microsoft.com/en-us/xamarin/android/platform/androidx for more details. The |
@dellis1972 I don't have any nuget packages Xamarin.Android.Support or any referencing it. Only AndroidX. Example project. I created a new .NET 6 Android project, changed activity_main.xml to AndroidBoundlayout and added an ID.
|
Ah. Are you using LayoutBindings? |
Ignore that, yes you are :) sorry. OK, that is where the issue is then. |
I would guess that there would need to be an if added to support both classic with PreserveAttribute and .NET 6 with DynamicDependencyAttribute. A additional property would be probably be needed to feed the MsBuild task, perhaps UsingAndroidNETSdk? |
|
Is the attribute even needed? This is the C# binding which is used by the developer so if unused constructors are removed it shouldn't be a problem? The file should also contain the autogenerated comment so any warnings would be ignored. |
A little more information on that: |
I'm still seeing this issue in NET 7 Android 33, even though #1051 is resolved. There is no autogenerated comment in generated/Binding.xxx.g.cs |
This change was too late to make it into .NET 7, I would suspect that it is fixed in .NET 8 Previews. |
Same issue in .NET 8. |
…ings Fixes dotnet#7480 * Remove the use of `PreserveAttribute` as we no longer support Xamarin Classic in main. * Add #pragma and code comments to fix certain CS* warnings which are emitted by the C# compiler. * Ignore a bunch of other warnings in the unit test.
Would it be possible to backport to .NET 8 if it's a limited change: only adding |
Yes, we can consider taking this one to .NET 8 servicing after it's merged: |
…ings Fixes dotnet#7480 * Remove the use of `PreserveAttribute` as we no longer support Xamarin Classic in main. * Add #pragma and code comments to fix certain CS* warnings which are emitted by the C# compiler. * Ignore a bunch of other warnings in the unit test.
…ings Fixes dotnet#7480 * Remove the use of `PreserveAttribute` as we no longer support Xamarin Classic in main. * Add #pragma and code comments to fix certain CS* warnings which are emitted by the C# compiler. * Ignore a bunch of other warnings in the unit test.
…ings Fixes dotnet#7480 * Remove the use of `PreserveAttribute` as we no longer support Xamarin Classic in main. * Add #pragma and code comments to fix certain CS* warnings which are emitted by the C# compiler. * Ignore a bunch of other warnings in the unit test.
…ings Fixes dotnet#7480 * Remove the use of `PreserveAttribute` as we no longer support Xamarin Classic in main. * Add #pragma and code comments to fix certain CS* warnings which are emitted by the C# compiler. * Ignore a bunch of other warnings in the unit test.
…ings Fixes dotnet#7480 * Remove the use of `PreserveAttribute` as we no longer support Xamarin Classic in main. * Add #pragma and code comments to fix certain CS* warnings which are emitted by the C# compiler. * Ignore a bunch of other warnings in the unit test.
Fixes: #7480 Context: e604833 When [Layout Bindings][0] are enabled, a set of `partial` classes will be generated which "mirrors" the `.axml` structure in C#. Consider: dotnet new android -n com.example.codebehind You enable Code-Behind by: 1. Setting the `$(AndroidGenerateLayoutBindings)` MSBuild property to `true`. 2. Using `android:id` on elements within `.axml` files. Consider this patch to the above `dotnet new`: diff --git a/Resources/layout/activity_main.xml b/Resources/layout/activity_main.xml index f949852..c74521c 100644 --- a/Resources/layout/activity_main.xml +++ b/Resources/layout/activity_main.xml @@ -8,6 +8,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" + android:id="@+id/text" android:text="@string/app_text" /> </RelativeLayout> diff --git a/com.example.codebehind.csproj b/com.example.codebehind.csproj index 3fdbcb5..8190f84 100644 --- a/com.example.codebehind.csproj +++ b/com.example.codebehind.csproj @@ -8,5 +8,6 @@ <ApplicationId>com.companyname.com.example.codebehind</ApplicationId> <ApplicationVersion>1</ApplicationVersion> <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> + <AndroidGenerateLayoutBindings>true</AndroidGenerateLayoutBindings> </PropertyGroup> </Project> The resulting output contains `$(IntermediateOutputPath)codebehind\Binding.activity_main.g.cs`, which declares a type based on the `.axml` file name, and a mirror of the structure: namespace Binding { // typename based on `activity_main.xml` filename sealed partial class activity_main : global::Xamarin.Android.Design.LayoutBinding { [global::Android.Runtime.PreserveAttribute (Conditional=true)] public activity_main (Activity client, …); // … // `text` is via `android:id="@+id/text"` public TextView text => …; } } The problem is the use of `PreserveAttribute` in the generated code; it's been `[Obsolete]` since e604833 (over two years ago), which means all projects using Layout Bindings and Layout Code-Behind always have [CS0618][1] warnings. Remove the emission of `PreserveAttribute`, so that CS0618 is no longer generated. Additionally, within the generated files disable the [CS1591][2] and [CS8981][3] warnings: * CS1591 is around missing XML documentation comments. These code behind files do not have XML documentation comments, so if/when `$(DocumentationFile)` is set, these will be emitted for the generated code. We do not currently plan on emitting XML documentation comments, so disable this warning. * CS8981 is emitted when a type name consists solely of lowercase characters. As the generated Binding types are based on the filename -- which is frequently all lowercase -- this warning may be emitted. Finally, add `#nullable enable` to `LayoutBinding.cs` and fix the nullable reference type warnings. [0]: https://github.com/xamarin/xamarin-android/blob/2f4e01ec15102dd9cd922cbd833f6482d69512b5/Documentation/guides/LayoutCodeBehind.md [1]: https://learn.microsoft.com/dotnet/csharp/language-reference/compiler-messages/cs0618 [2]: https://learn.microsoft.com/dotnet/csharp/language-reference/compiler-messages/cs1591 [3]: https://learn.microsoft.com/dotnet/csharp/language-reference/compiler-messages/warning-waves#cs8981---the-type-name-only-contains-lower-cased-ascii-characters
Android application type
Android for .NET (net6.0-android, etc.)
Affected platform version
VS2022 17.3.6
Description
We are using a lot of AndroidBoundLayout in our app but this results in 2 warnings per layout file:
We would like to get to 0 build warnings :)
Steps to Reproduce
Did you find any workaround?
No response
Relevant log output
No response
The text was updated successfully, but these errors were encountered: