Log versions of all used DLLs

I want to register versions of all DLLs that my .NET application uses. It does not matter if the log output is generated at startup or the first use of each DLL.

The first solution that occurred to me was to iterate over all the DLL files that are in the same directory as my assembly. But is this the best option I have? Is there a better way to do this? It is important that the solution also runs on the .NET-Compact-Framework.

+6
logging compact-framework
source share
6 answers

Edit: I tested and verified that this works in the .NET Compact Framework.

You can do this using Mono.Cecil , a powerful tool that allows you to open and validate .NET assemblies at the IL level without even loading them into AppDomain.

string path = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase; // If using Mono.Cecil 0.6.9.0: AssemblyDefinition myAssembly = AssemblyFactory.GetAssembly(path); // If using Mono.Cecil 0.9.1.0: AssemblyDefinition myAssembly = AssemblyDefinition.ReadAssembly(path); // from there, you can inspect the assembly references foreach (ModuleDefinition module in myAssembly.Modules) { foreach (AssemblyNameReference assemblyReference in module.AssemblyReferences) { // do something with the reference eg get name, version, etc string fullName = assemblyReference.FullName; Version version = assemblyReference.Version; } } 
+6
source share

I'm not sure if it is available on CF, but in normal .NET I would just use AppDomain.GetAssemblies() .

You can use the AppDomain.AssemblyLoad event to notify you of the assembly loading.

0
source share

You might be able to use Dependency Walker , and just use the command line options to execute it as a subprocess. According to frequently asked questions, it works with Windows CE modules, although it does not work on CE devices, which may not suit your needs.

0
source share

Use the AppDomain.AssemblyLoad event.

eg.

 AppDomain.CurrentDomain.AssemblyLoad+=(s, e) => Console.WriteLine("loaded: "+e.LoadedAssembly.FullName); 
0
source share
 public void LogAssemblies() { foreach(Assembly asm in AppDomain.CurrentDomain.GetAssemblies()) { AssemblyName assemblyName = asm.GetName(); string simpleName = assemblyName.Name; string version = assemblyName.Version.ToString(); // do something with these } } 

EDIT: Woops, looks like AppDomain.GetAssemblies () is not in a compact structure.

0
source share

I assume that an interesting algorithm is to serialize the assemblies that you use, and then at startup you will deserialize your configuration and compare it with the version that each DLL has. Then, after updating the version, you serialize the new version of your configuration and write the name and version of your assembly to your log file or so on.

Keep in mind that the most important thing to consider is getting everyone to do what you need. Nothing else matters. Once he has completed the required work, there may be room for improvement. But first, earn! You will just see what needs to be improved after that.

0
source share

All Articles