@@ -14,6 +14,7 @@ public class RemoveResourceDesignerStep : BaseStep
1414 {
1515 TypeDefinition mainDesigner = null ;
1616 AssemblyDefinition mainAssembly = null ;
17+ CustomAttribute mainDesignerAttribute ;
1718 Dictionary < string , int > designerConstants ;
1819 Regex opCodeRegex = new Regex ( @"([\w]+): ([\w]+) ([\w.]+) ([\w:./]+)" ) ;
1920
@@ -24,40 +25,47 @@ protected override void Process ()
2425 if ( config == null )
2526 return ;
2627 foreach ( var asm in config . Assemblies ) {
27- if ( FindResourceDesigner ( asm , isApplication : true , designer : out mainDesigner ) ) {
28+ if ( FindResourceDesigner ( asm , isApplication : true , designer : out mainDesigner , designerAttribute : out mainDesignerAttribute ) ) {
2829 mainAssembly = asm ;
2930 break ;
3031 }
3132 }
3233 if ( mainDesigner == null ) {
33- Context . LogMessage ( $ " Main Designer not found.") ;
34+ Context . LogMessage ( $ " Main Designer not found.") ;
3435 return ;
3536 }
36- Context . LogMessage ( $ " Main Designer found { mainDesigner . FullName } .") ;
37+ Context . LogMessage ( $ " Main Designer found { mainDesigner . FullName } .") ;
3738 designerConstants = BuildResourceDesignerFieldLookup ( mainDesigner ) ;
3839 }
3940
4041 protected override void EndProcess ( )
4142 {
43+ Context . LogMessage ( $ " End Process Called.") ;
4244 if ( mainDesigner != null ) {
45+ Context . LogMessage ( $ " Removing Main Designer { mainDesigner . FullName } ") ;
4346 RemoveDesigner ( mainDesigner ) ;
47+ Context . LogMessage ( $ " Removing Designer Custom Attribute { mainDesignerAttribute . AttributeType . FullName } ") ;
48+ mainAssembly . CustomAttributes . Remove ( mainDesignerAttribute ) ;
49+ Context . LogMessage ( $ " Setting Action on { mainAssembly . Name } to Save.") ;
4450 Annotations . SetAction ( mainAssembly , AssemblyAction . Save ) ;
4551 }
4652 }
4753
48- bool FindResourceDesigner ( AssemblyDefinition assembly , bool isApplication , out TypeDefinition designer )
54+ bool FindResourceDesigner ( AssemblyDefinition assembly , bool isApplication , out TypeDefinition designer , out CustomAttribute designerAttribute )
4955 {
5056 string designerFullName = null ;
5157 designer = null ;
58+ designerAttribute = null ;
5259 foreach ( CustomAttribute attribute in assembly . CustomAttributes )
5360 {
5461 if ( attribute . AttributeType . FullName == "Android.Runtime.ResourceDesignerAttribute" )
5562 {
63+ designerAttribute = attribute ;
5664 if ( attribute . HasProperties )
5765 {
5866 foreach ( var p in attribute . Properties )
5967 {
60- if ( p . Name == "IsApplication" && ( bool ) p . Argument . Value == isApplication )
68+ if ( p . Name == "IsApplication" && ( bool ) p . Argument . Value == ( isApplication ? isApplication : ( bool ) p . Argument . Value ) )
6169 {
6270 designerFullName = attribute . ConstructorArguments [ 0 ] . Value . ToString ( ) ;
6371 break ;
@@ -172,10 +180,19 @@ protected override void ProcessAssembly (AssemblyDefinition assembly)
172180 if ( MonoAndroidHelper . IsFrameworkAssembly ( fileName ) )
173181 return ;
174182
175- Context . LogMessage ( $ " Fixing up { assembly . Name . Name } ") ;
176- if ( ! FindResourceDesigner ( assembly , false , out TypeDefinition localDesigner ) ) {
177- Context . LogMessage ( $ " { assembly . Name . Name } does not have a designer file.") ;
178- return ;
183+ Context . LogMessage ( $ " Fixing up { assembly . Name . Name } ") ;
184+ TypeDefinition localDesigner = null ;
185+ CustomAttribute designerAttribute ;
186+ if ( assembly != mainAssembly ) {
187+ Context . LogMessage ( $ " { assembly . Name . Name } is not the main assembly. ") ;
188+ if ( ! FindResourceDesigner ( assembly , isApplication : false , designer : out localDesigner , designerAttribute : out designerAttribute ) ) {
189+ Context . LogMessage ( $ " { assembly . Name . Name } does not have a designer file.") ;
190+ return ;
191+ }
192+ } else {
193+ Context . LogMessage ( $ " { assembly . Name . Name } is the main assembly. ") ;
194+ localDesigner = mainDesigner ;
195+ designerAttribute = mainDesignerAttribute ;
179196 }
180197
181198 Context . LogMessage ( $ " { assembly . Name . Name } has designer { localDesigner . FullName } .") ;
@@ -187,8 +204,12 @@ protected override void ProcessAssembly (AssemblyDefinition assembly)
187204 ProcessTypeR ( type , localDesigner ) ;
188205 }
189206 }
190-
191- RemoveDesigner ( localDesigner ) ;
207+ if ( assembly != mainAssembly ) {
208+ RemoveDesigner ( localDesigner ) ;
209+ if ( designerAttribute != null ) {
210+ assembly . CustomAttributes . Remove ( designerAttribute ) ;
211+ }
212+ }
192213 }
193214 }
194215}
0 commit comments