-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Build.Tasks] Don't remove resx Resource.designer.cs (#…
…9057) Fixes: #9163 Context: dc3ccf2 Context: 3ec1b15 With the release of the new Resource Designer assembly (dc3ccf2) purposely removed the existing legacy `Resource.designer.cs` file from the `@(Compile)` ItemGroup. This is so that we did not get any clashes with the new system. Unfortunately the name `Resource.designer.cs` is also used by developers as the name for the generated class when using `.resx` files. As a result we got the following CS0234 error because the class was disappearing: error CS0234: The type or namespace name 'Resources' does not exist in the namespace 'StringResourcesBug' (are you missing an assembly reference?) It turns out that the `_RemoveLegacyDesigner` was being a bit too aggressive with its removal of files. Because it was matching on filename only it was removing files which had nothing to do with Android Resources. This would cause the above CS0234 error. The fix in this case is to check for additional metadata. In the case of `.resx` file designers they typically have `%(DependentUpon)` metadata to signal that they are generated from the `.resx`. We should check `%(DependentUpon)` to make sure it is NOT set before removing a file from the `@(Compile)` item group. A new unit test was added to test this fix and it worked. But it did show up one other issue: in certain cases we would end up with two `Resource` classes in the same namespace. This would then cause the following build error. error CS0260: Missing partial modifier on declaration of type 'Resource'; another partial declaration of this type exists This is because the two classes had different modifiers. We could also get an error if the access modifiers are different (`public` vs `internal`). Add a new MSBuild property `$(AndroidResourceDesignerClassModifier)`. This property defaults to `public`, but can be overridden by the user to control the access modifier of the generated class. Also we have to remove the `[GeneratedCode]` Attribute usage on the generated `Resource` class, as it can conflict with the one that is auto added to the `Resource.designer.cs` generated by the `resx` code generator. If we leave this in place we get the following error. __Microsoft.Android.Resource.Designer.cs(15,3,15,16): error CS0579: Duplicate 'GeneratedCode' attribute Unfortunately [`GeneratedCodeAttribute`][1] is marked as `AllowMultiple=false` and in this case there is no way to know if it exists on the class already as its a `partial` class. [1]: https://learn.microsoft.com/en-us/dotnet/api/system.codedom.compiler.generatedcodeattribute?view=net-8.0
- Loading branch information
1 parent
1857f28
commit 15a1429
Showing
11 changed files
with
86 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
title: .NET for Android error XA1038 | ||
description: XA1038 error code | ||
ms.date: 06/27/2024 | ||
--- | ||
# .NET for Android error XA1038 | ||
|
||
## Example messages | ||
|
||
``` | ||
The 'AndroidResourceDesignerClassModifier' MSBuild property has an invalid value of 'foo'. A valid value is one of: 'public', 'internal'. | ||
``` | ||
|
||
## Solution | ||
|
||
Edit your csproj directly and remove the referenced MSBuild property. | ||
|
||
Test your project to ensure the new behavior is functionally equivalent. | ||
|
||
If not, file an [issue](https://github.com/xamarin/xamarin-android/issues) so a | ||
solution can be found before the deprecated flag is removed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters