How to get C # .NET Compiler Assembly GUID

I am trying to find out when the assembly changed (even if the version number is the same).

The best effort at the moment is that it has been recompiled, so would like to use the same element that uses MSBuild, which, in my opinion, is the GUID of the files stored in the metadata? (According to .NET file format )

Is there any way to access this information without reinventing the wheel and not dropping files into bytes?

+4
source share
2 answers

Well, it looks like assemblies don't have associated GUIDs. Modules, classes, methods, fields have a GUID, and the "GUID" stream in the assembly is the place to store them.

If you want to access assembly meta-information (for example, the GUID of your main module), this Mono.Cecilmight be a good option.

But instead, you can achieve this by calibrating the checksum using a hash function or just looking at the date of change. System.IO.FilesystemWatchercan tell you if you do not want to access the intervally file.

+1
source

Try storing the last modified build date in a variable and checking it. Here's how to get the latest modified build date:

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.FileInfo fileInfo = new System.IO.FileInfo(assembly.Location);
DateTime lastModified = fileInfo.LastWriteTime;
0
source

Source: https://habr.com/ru/post/1683416/


All Articles