44using System . IO ;
55
66using Java . Interop . Tools . Cecil ;
7+ using Microsoft . Android . Build . Tasks ;
8+ using Microsoft . Build . Utilities ;
79using Mono . Cecil ;
10+ using Xamarin . Android . Tools ;
811
912namespace Xamarin . Android . Tasks
1013{
@@ -13,12 +16,14 @@ class MarshalMethodsAssemblyRewriter
1316 IDictionary < string , IList < MarshalMethodEntry > > methods ;
1417 ICollection < AssemblyDefinition > uniqueAssemblies ;
1518 IDictionary < string , HashSet < string > > assemblyPaths ;
19+ TaskLoggingHelper log ;
1620
17- public MarshalMethodsAssemblyRewriter ( IDictionary < string , IList < MarshalMethodEntry > > methods , ICollection < AssemblyDefinition > uniqueAssemblies , IDictionary < string , HashSet < string > > assemblyPaths )
21+ public MarshalMethodsAssemblyRewriter ( IDictionary < string , IList < MarshalMethodEntry > > methods , ICollection < AssemblyDefinition > uniqueAssemblies , IDictionary < string , HashSet < string > > assemblyPaths , TaskLoggingHelper log )
1822 {
1923 this . methods = methods ?? throw new ArgumentNullException ( nameof ( methods ) ) ;
2024 this . uniqueAssemblies = uniqueAssemblies ?? throw new ArgumentNullException ( nameof ( uniqueAssemblies ) ) ;
2125 this . assemblyPaths = assemblyPaths ?? throw new ArgumentNullException ( nameof ( assemblyPaths ) ) ;
26+ this . log = log ?? throw new ArgumentNullException ( nameof ( log ) ) ;
2227 }
2328
2429 public void Rewrite ( DirectoryAssemblyResolver resolver )
@@ -87,11 +92,12 @@ public void Rewrite (DirectoryAssemblyResolver resolver)
8792 void MoveFile ( string source , string target )
8893 {
8994 Console . WriteLine ( $ "Moving '{ source } ' => '{ target } '") ;
90- if ( File . Exists ( target ) ) {
91- File . Delete ( target ) ;
95+ Files . CopyIfChanged ( source , target ) ;
96+ try {
97+ File . Delete ( source ) ;
98+ } catch ( Exception ex ) {
99+ log . LogWarning ( $ "Unable to delete source file '{ source } ' when moving it to '{ target } '") ;
92100 }
93-
94- File . Move ( source , target ) ;
95101 }
96102 }
97103
0 commit comments