-
Notifications
You must be signed in to change notification settings - Fork 564
[Xamarin.Android.Build.Tasks] Add support for '<AndroidNamespaceReplacement>'. #6643
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
Conversation
b1ba3b9 to
3776da5
Compare
|
The |
| // ex: obj/Debug/generated/msbuild-metadata.xml | ||
| var transform_file = Path.Combine (OutputDirectory, "..", "msbuild-metadata.xml"); | ||
|
|
||
| var xml = new XDocument (); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure you need the XDocument at all? XElement.WriteTo() also works…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
|
@jpobst: the new item group should also be documented in: https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/building-apps/build-items.md |
| xml.Add (root); | ||
|
|
||
| foreach (var nt in NamespaceTransforms) | ||
| xml.Root.Add (new XElement ("ns-replace", new XAttribute ("source", nt.ItemSpec), new XAttribute ("replacement", nt.GetMetadata ("replacement")))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we emit a warning/error if %(Replacement) is blank? I'm just thinking if someone put Replace="AndroidX" on accident, they won't know what's wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
%(Replacement) being blank is valid and useful. I guess the question is should we require users to provide the blank attribute Replacement=""? Perhaps we should?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added and documented new error.
| { | ||
| var cmd = GetCommandLineBuilder (); | ||
|
|
||
| if (NamespaceTransforms?.Any () == true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably fine, but feels weird. Would this be just as good?
| if (NamespaceTransforms?.Any () == true) { | |
| if (NamespaceTransforms != null && NamespaceTransforms.Length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, those are equivalent. I think Any and null-check operator is generally considered the modern "best practice".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I generally avoid using System.Linq;, but there are some cases where OrderBy() is ok.
This is fine, though.
d5e6aca to
476d740
Compare
476d740 to
3607637
Compare
Context: dotnet/java-interop#727
Add an MSBuild equivalent to the
<ns-replace>metadata feature added in dotnet/java-interop#727.This takes namespace transforms like:
And places them into a generated
msbuild-metadata.xmlfile that is passed togenerator:Today, this only supports
<ns-replace>metadata, but it could be expanded in the future if we feel that allowing other metadata is desirable. (I am personally skeptical 😁.)