3 using System.Collections.Generic;
4 using System.Reflection;
7 using SiliconStudio.Core.Diagnostics;
8 using SiliconStudio.Core.Storage;
10 namespace SiliconStudio.BuildEngine
12 internal static class AssemblyHash
14 private static readonly
Logger Log = GlobalLogger.GetLogger(
"AssemblyHash");
21 public static string ComputeAssemblyHash(Assembly assembly)
26 if (!assemblyToHash.TryGetValue(assembly, out hash))
28 var assemblies =
new HashSet<Assembly>();
29 var text =
new StringBuilder();
30 ComputeAssemblyHash(assembly, assemblies, text);
31 hash = ObjectId.FromBytes(Encoding.UTF8.GetBytes(text.ToString())).ToString();
32 assemblyToHash.Add(assembly, hash);
33 Log.Info(
"Assembly Hash [{0}] => [{1}]", assembly.GetName().Name, hash);
39 private static readonly Dictionary<Assembly, string> assemblyToHash =
new Dictionary<Assembly, string>();
41 private static void ComputeAssemblyHash(Assembly assembly, HashSet<Assembly> assemblies, StringBuilder outputString)
43 if (assemblies.Contains(assembly))
46 outputString.Append(assembly.FullName);
48 var attribute = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>();
49 if (attribute != null)
51 outputString.Append(
",").Append(attribute.Version);
52 outputString.AppendLine();
55 assemblies.Add(assembly);
56 foreach (var assemblyName
in assembly.GetReferencedAssemblies())
58 var assemblyRef = Assembly.Load(assemblyName);
59 ComputeAssemblyHash(assemblyRef, assemblies, outputString);
Base implementation for ILogger.
Output message to log right away.