@@ -28,56 +28,57 @@ public override bool Execute ()
2828 Log . LogDebugMessage ( "StripEmbeddedLibraries Task" ) ;
2929 Log . LogDebugTaskItems ( " Assemblies: " , Assemblies ) ;
3030
31- var res = new DirectoryAssemblyResolver ( Log . LogWarning , true ) ;
32- foreach ( var assembly in Assemblies )
33- res . Load ( Path . GetFullPath ( assembly . ItemSpec ) ) ;
31+ using ( var res = new DirectoryAssemblyResolver ( Log . LogWarning , true ) ) {
32+ foreach ( var assembly in Assemblies )
33+ res . Load ( Path . GetFullPath ( assembly . ItemSpec ) , new ReaderParameters { ReadWrite = true } ) ;
3434
35- foreach ( var assemblyName in Assemblies ) {
36- var suffix = assemblyName . ItemSpec . EndsWith ( ".dll" ) ? String . Empty : ".dll" ;
37- string hintPath = assemblyName . GetMetadata ( "HintPath" ) . Replace ( Path . AltDirectorySeparatorChar , Path . DirectorySeparatorChar ) ;
38- string fileName = assemblyName . ItemSpec + suffix ;
39- if ( ! String . IsNullOrEmpty ( hintPath ) && ! File . Exists ( hintPath ) ) // ignore invalid HintPath
40- hintPath = null ;
41- string assemblyPath = String . IsNullOrEmpty ( hintPath ) ? fileName : hintPath ;
42- if ( MonoAndroidHelper . IsFrameworkAssembly ( fileName ) && ! MonoAndroidHelper . FrameworkEmbeddedJarLookupTargets . Contains ( Path . GetFileName ( fileName ) ) )
43- continue ;
35+ foreach ( var assemblyName in Assemblies ) {
36+ var suffix = assemblyName . ItemSpec . EndsWith ( ".dll" ) ? String . Empty : ".dll" ;
37+ string hintPath = assemblyName . GetMetadata ( "HintPath" ) . Replace ( Path . AltDirectorySeparatorChar , Path . DirectorySeparatorChar ) ;
38+ string fileName = assemblyName . ItemSpec + suffix ;
39+ if ( ! String . IsNullOrEmpty ( hintPath ) && ! File . Exists ( hintPath ) ) // ignore invalid HintPath
40+ hintPath = null ;
41+ string assemblyPath = String . IsNullOrEmpty ( hintPath ) ? fileName : hintPath ;
42+ if ( MonoAndroidHelper . IsFrameworkAssembly ( fileName ) && ! MonoAndroidHelper . FrameworkEmbeddedJarLookupTargets . Contains ( Path . GetFileName ( fileName ) ) )
43+ continue ;
4444
45- var assembly = res . GetAssembly ( assemblyPath ) ;
46- bool assembly_modified = false ;
47- foreach ( var mod in assembly . Modules ) {
48- // embedded jars
49- var resjars = mod . Resources . Where ( r => r . Name . EndsWith ( ".jar" , StringComparison . InvariantCultureIgnoreCase ) ) . Select ( r => ( EmbeddedResource ) r ) ;
50- foreach ( var resjar in resjars . ToArray ( ) ) {
51- Log . LogDebugMessage ( " Stripped {0}" , resjar . Name ) ;
52- mod . Resources . Remove ( resjar ) ;
53- assembly_modified = true ;
45+ var assembly = res . GetAssembly ( assemblyPath , new ReaderParameters { ReadWrite = true } ) ;
46+ bool assembly_modified = false ;
47+ foreach ( var mod in assembly . Modules ) {
48+ // embedded jars
49+ var resjars = mod . Resources . Where ( r => r . Name . EndsWith ( ".jar" , StringComparison . InvariantCultureIgnoreCase ) ) . Select ( r => ( EmbeddedResource ) r ) ;
50+ foreach ( var resjar in resjars . ToArray ( ) ) {
51+ Log . LogDebugMessage ( " Stripped {0}" , resjar . Name ) ;
52+ mod . Resources . Remove ( resjar ) ;
53+ assembly_modified = true ;
54+ }
55+ // embedded AndroidNativeLibrary archive
56+ var nativezip = mod . Resources . FirstOrDefault ( r => r . Name == "__AndroidNativeLibraries__.zip" ) as EmbeddedResource ;
57+ if ( nativezip != null ) {
58+ Log . LogDebugMessage ( " Stripped {0}" , nativezip . Name ) ;
59+ mod . Resources . Remove ( nativezip ) ;
60+ assembly_modified = true ;
61+ }
62+ // embedded AndroidResourceLibrary archive
63+ var reszip = mod . Resources . FirstOrDefault ( r => r . Name == "__AndroidLibraryProjects__.zip" ) as EmbeddedResource ;
64+ if ( reszip != null ) {
65+ Log . LogDebugMessage ( " Stripped {0}" , reszip . Name ) ;
66+ mod . Resources . Remove ( reszip ) ;
67+ assembly_modified = true ;
68+ }
5469 }
55- // embedded AndroidNativeLibrary archive
56- var nativezip = mod . Resources . FirstOrDefault ( r => r . Name == "__AndroidNativeLibraries__.zip" ) as EmbeddedResource ;
57- if ( nativezip != null ) {
58- Log . LogDebugMessage ( " Stripped {0}" , nativezip . Name ) ;
59- mod . Resources . Remove ( nativezip ) ;
60- assembly_modified = true ;
61- }
62- // embedded AndroidResourceLibrary archive
63- var reszip = mod . Resources . FirstOrDefault ( r => r . Name == "__AndroidLibraryProjects__.zip" ) as EmbeddedResource ;
64- if ( reszip != null ) {
65- Log . LogDebugMessage ( " Stripped {0}" , reszip . Name ) ;
66- mod . Resources . Remove ( reszip ) ;
67- assembly_modified = true ;
68- }
69- }
70- if ( assembly_modified ) {
71- Log . LogDebugMessage ( " The stripped library is saved as {0}" , assemblyPath ) ;
70+ if ( assembly_modified ) {
71+ Log . LogDebugMessage ( " The stripped library is saved as {0}" , assemblyPath ) ;
7272
73- // Output assembly needs to regenerate symbol file even if no IL/metadata was touched
74- // because Cecil still rewrites all assembly types in Cecil order (type A, nested types of A, type B, etc)
75- // and not in the original order causing symbols if original order doesn't match Cecil order
76- var wp = new WriterParameters ( ) {
77- WriteSymbols = assembly . MainModule . HasSymbols
78- } ;
73+ // Output assembly needs to regenerate symbol file even if no IL/metadata was touched
74+ // because Cecil still rewrites all assembly types in Cecil order (type A, nested types of A, type B, etc)
75+ // and not in the original order causing symbols if original order doesn't match Cecil order
76+ var wp = new WriterParameters ( ) {
77+ WriteSymbols = assembly . MainModule . HasSymbols
78+ } ;
7979
80- assembly . Write ( assemblyPath , wp ) ;
80+ assembly . Write ( wp ) ;
81+ }
8182 }
8283 }
8384 return true ;
0 commit comments