Hi, Just use asmDef.Name.Hash[Algorithm]?
Regards, Alex 2011/6/18 Florian <[email protected]>: > Hi there, > > I am trying to encounter wether two assemblies have actually the same > content (i.e. being build from the same sources). > > My first attempt was to create a MD5 hash on the assembly file content > and compare that MD5 hash to the hash of another assembly. This proved > to be not working because there are some fields within the assembly > file format that vary on every build, even if built from the exact > same sources. > One example of these fields is the MVID (ModuleVersionID) - see also: > http://stackoverflow.com/questions/2940857/determine-whether-net-assemblies-were-built-from-the-same-source. > The StackOverflow post says that with .NET 4 there are now 3 different > fields that vary on each build. > > I really need to find a fast way to compare if the data that I cached > away from an assembly needs to be updated (because the assembly > content has changed - i.e. it has been built from changed sources). > So would it be possible to create a GetAssemblyHash() method in the > AssemblyDefinition class that basically takes the file content > bytearray, blanks out those fields that vary on each build and creates > a md5 hash on it? > > I would propably give it a go on my own but I guess my knowledge about > the assembly file format is just not enough to make a stable solution. > > If it helps, here is how I did the Md5 Hashing: > > var md5 = new MD5CryptoServiceProvider(); > var result = md5.ComputeHash(byteArray); > var sb = new StringBuilder(); > for (var i = 0; i < result.Length; i++) > sb.Append(result[i].ToString("X2")); > return sb.ToString(); > > Thanks a lot for any help, its really appreciated. > > Best regards > > Florian > > -- > -- > mono-cecil -- -- mono-cecil
