Migrate GenerateProguardConfiguration from ILLink step to MSBuild task#10694
Migrate GenerateProguardConfiguration from ILLink step to MSBuild task#10694
Conversation
The new task runs AfterTargets="ILLink" and uses System.Reflection.Metadata instead of Mono.Cecil to scan linked assemblies.
There was a problem hiding this comment.
Pull request overview
This PR migrates the GenerateProguardConfiguration functionality from an ILLink custom step (using Mono.Cecil) to an MSBuild task (using System.Reflection.Metadata). The task runs after the ILLink target and scans linked assemblies to generate ProGuard configuration rules for Android callable wrapper (ACW) types.
Changes:
- Added new MSBuild task
GenerateProguardConfigurationusing System.Reflection.Metadata for assembly inspection - Updated MSBuild targets to invoke the new task after ILLink instead of as a linker custom step
- Removed the old ILLink step implementation that used Mono.Cecil
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/Xamarin.Android.Build.Tasks/Tasks/GenerateProguardConfiguration.cs | New MSBuild task that scans linked assemblies for RegisterAttribute and generates ProGuard keep rules |
| src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.ILLink.targets | Added targets to prepare linked assemblies and invoke the new task; removed old linker custom step configuration |
| src/Microsoft.Android.Sdk.ILLink/GenerateProguardConfiguration.cs | Deleted old ILLink step implementation |
| if (!Directory.Exists (dir)) | ||
| Directory.CreateDirectory (dir); |
There was a problem hiding this comment.
Path.GetDirectoryName can return null when the path doesn't contain directory information. The variable 'dir' should be checked for null before being passed to Directory.Exists and Directory.CreateDirectory. Consider using a pattern like the one in KeyTool.cs line 42 where the result is checked with IsNullOrEmpty before use.
| if (!Directory.Exists (dir)) | |
| Directory.CreateDirectory (dir); | |
| if (!dir.IsNullOrEmpty () && !Directory.Exists (dir)) { | |
| Directory.CreateDirectory (dir); | |
| } |
| var args = attr.GetCustomAttributeArguments (); | ||
| if (args.FixedArguments.Length >= 2 && | ||
| args.FixedArguments[0].Value is string jname && | ||
| args.FixedArguments[1].Value is string jargs) { |

The new task runs AfterTargets="ILLink" and uses System.Reflection.Metadata instead of Mono.Cecil to scan linked assemblies.