@@ -196,6 +196,8 @@ public static void SignAssemblies(IEnumerable<InputOutputFilePair> assemblyInput
196196 }
197197 }
198198
199+ Log ( "1. Loading assemblies..." ) ;
200+
199201 // Convert all paths into AssemblyInfo objects.
200202 var allAssemblies = new HashSet < AssemblyInfo > ( ) ;
201203
@@ -208,24 +210,30 @@ public static void SignAssemblies(IEnumerable<InputOutputFilePair> assemblyInput
208210 {
209211 try
210212 {
211- var tempFilePath = Path . Combine ( tempPath , Path . GetFileName ( inputOutpuFilePair . InputFilePath ) ) ;
213+ var tempFilePath = Path . Combine ( tempPath , $ " { Path . GetFileNameWithoutExtension ( inputOutpuFilePair . InputFilePath ) } . { Guid . NewGuid ( ) } { Path . GetExtension ( inputOutpuFilePair . InputFilePath ) } " ) ;
212214 File . Copy ( inputOutpuFilePair . InputFilePath , tempFilePath , true ) ;
213215
214- if ( File . Exists ( Path . ChangeExtension ( inputOutpuFilePair . InputFilePath , ".pdb" ) ) )
216+ if ( inputOutpuFilePair . HasSymbols )
215217 {
216- File . Copy ( Path . ChangeExtension ( inputOutpuFilePair . InputFilePath , ".pdb" ) , Path . ChangeExtension ( tempFilePath , ".pdb" ) , true ) ;
218+ File . Copy ( inputOutpuFilePair . InputPdbPath , Path . ChangeExtension ( tempFilePath , ".pdb" ) , true ) ;
217219 }
218220
219221 tempFilePathToInputOutputFilePairMap . Add ( tempFilePath , inputOutpuFilePair ) ;
220222
221223 allAssemblies . Add ( new AssemblyInfo ( tempFilePath , probingPaths ) ) ;
222224 }
225+ catch ( BadImageFormatException ex )
226+ {
227+ Log ( $ " Unsupported assembly '{ inputOutpuFilePair . InputFilePath } ': { ex . Message } ") ;
228+ }
223229 catch ( Exception ex )
224230 {
225- Log ( ex . ToString ( ) ) ;
231+ Log ( $ " Failed to load assembly ' { inputOutpuFilePair . InputFilePath } ': { ex . Message } " ) ;
226232 }
227233 }
228234
235+ Log ( "2. Checking assembly references..." ) ;
236+
229237 try
230238 {
231239 // Start with assemblies that are not signed.
@@ -240,7 +248,7 @@ public static void SignAssemblies(IEnumerable<InputOutputFilePair> assemblyInput
240248
241249 foreach ( var assembly in allAssemblies )
242250 {
243- Log ( $ "Checking assembly references in '{ assembly . FilePath } '.") ;
251+ Log ( $ " Checking assembly references in '{ tempFilePathToInputOutputFilePairMap [ assembly . FilePath ] . InputFilePath } '.") ;
244252
245253 foreach ( var reference in assembly . Definition . MainModule . AssemblyReferences
246254 . Where ( reference => set . Contains ( reference . Name ) ) )
@@ -250,10 +258,12 @@ public static void SignAssemblies(IEnumerable<InputOutputFilePair> assemblyInput
250258 }
251259 }
252260
261+ Log ( "3. Strong-name unsigned assemblies..." ) ;
262+
253263 // Strong-name sign all the unsigned assemblies.
254264 foreach ( var assembly in assembliesToProcess )
255265 {
256- Log ( $ "Signing assembly '{ assembly . FilePath } '.") ;
266+ Log ( $ " Signing assembly '{ tempFilePathToInputOutputFilePairMap [ assembly . FilePath ] . InputFilePath } '.") ;
257267
258268 var name = assembly . Definition . Name ;
259269 name . HashAlgorithm = AssemblyHashAlgorithm . SHA1 ;
@@ -262,6 +272,8 @@ public static void SignAssemblies(IEnumerable<InputOutputFilePair> assemblyInput
262272 name . Attributes |= AssemblyAttributes . PublicKey ;
263273 }
264274
275+ Log ( "4. Fix InternalVisibleToAttribute references..." ) ;
276+
265277 // Fix InternalVisibleToAttribute.
266278 foreach ( var assembly in allAssemblies )
267279 {
@@ -278,7 +290,7 @@ public static void SignAssemblies(IEnumerable<InputOutputFilePair> assemblyInput
278290
279291 if ( signedAssembly != null )
280292 {
281- Log ( $ "Fixing { signedAssembly . Definition . Name . Name } friend reference in assembly '{ assembly . FilePath } '.") ;
293+ Log ( $ " Fixing { signedAssembly . Definition . Name . Name } friend reference in assembly '{ tempFilePathToInputOutputFilePairMap [ assembly . FilePath ] . InputFilePath } '.") ;
282294
283295 var assemblyName = signedAssembly . Definition . Name . Name + ", PublicKey=" + BitConverter . ToString ( signedAssembly . Definition . Name . PublicKey ) . Replace ( "-" , string . Empty ) ;
284296 var updatedArgument = new CustomAttributeArgument ( argument . Type , assemblyName ) ;
@@ -290,6 +302,8 @@ public static void SignAssemblies(IEnumerable<InputOutputFilePair> assemblyInput
290302 }
291303 }
292304
305+ Log ( "5. Fix BAML references..." ) ;
306+
293307 // Fix BAML references.
294308 foreach ( var assembly in allAssemblies )
295309 {
@@ -358,7 +372,7 @@ public static void SignAssemblies(IEnumerable<InputOutputFilePair> assemblyInput
358372
359373 if ( modifyResource )
360374 {
361- Log ( $ "Replacing BAML entry in assembly '{ assembly . FilePath } '.") ;
375+ Log ( $ " Replacing BAML entry in assembly '{ tempFilePathToInputOutputFilePairMap [ assembly . FilePath ] . InputFilePath } '.") ;
362376
363377 resources . RemoveAt ( resIndex ) ;
364378 writer . Generate ( ) ;
@@ -373,6 +387,8 @@ public static void SignAssemblies(IEnumerable<InputOutputFilePair> assemblyInput
373387 }
374388 }
375389
390+ Log ( "6. Save assembly changes..." ) ;
391+
376392 // Write all updated assemblies.
377393 foreach ( var assembly in assembliesToProcess . Where ( a => ! a . Definition . Name . IsRetargetable ) )
378394 {
@@ -388,15 +404,15 @@ public static void SignAssemblies(IEnumerable<InputOutputFilePair> assemblyInput
388404 }
389405 }
390406
391- Log ( $ "Saving changes to assembly '{ inputOutpuFilePair . OutputFilePath } '.") ;
407+ Log ( $ " Saving changes to assembly '{ inputOutpuFilePair . OutputFilePath } '.") ;
392408
393409 try
394410 {
395411 assembly . Save ( inputOutpuFilePair . OutputFilePath , keyPair ) ;
396412 }
397413 catch ( NotSupportedException ex )
398414 {
399- Log ( $ "Failed to save assembly '{ inputOutpuFilePair . OutputFilePath } ': { ex . Message } ") ;
415+ Log ( $ " Failed to save assembly '{ inputOutpuFilePair . OutputFilePath } ': { ex . Message } ") ;
400416
401417 if ( inputOutpuFilePair . IsSameFile )
402418 {
@@ -419,6 +435,8 @@ public static void SignAssemblies(IEnumerable<InputOutputFilePair> assemblyInput
419435 }
420436 finally
421437 {
438+ Log ( "7. Cleanup..." ) ;
439+
422440 tempFilePathToInputOutputFilePairMap . Clear ( ) ;
423441
424442 foreach ( var assembly in allAssemblies )
@@ -432,7 +450,7 @@ public static void SignAssemblies(IEnumerable<InputOutputFilePair> assemblyInput
432450 }
433451 catch ( Exception ex )
434452 {
435- Log ( $ "Failed to delete temp working directory '{ tempPath } ': { ex . Message } ") ;
453+ Log ( $ " Failed to delete temp working directory '{ tempPath } ': { ex . Message } ") ;
436454 }
437455 }
438456 }
0 commit comments