Reputation: 9123
I've just started using C# and am currently trying to create a class that will compare the version of all dll files with a version string in my database.
However, I am not sure how to get all dll files that belong to my solution. I've tried the following:
Assembly[] applicationDLLs = AppDomain.CurrentDomain.GetAssemblies();
I found this on a forum somewhere. But I don't know what using statements are required and if this is valid code at all.
Can any of you point me in the right direction?
Upvotes: 2
Views: 2259
Reputation: 186688
Since an assembly can contain several dlls (Module
s) you can, technically, try
var result = AppDomain
.CurrentDomain
.GetAssemblies()
.SelectMany(asm => asm.GetModules())
.Select(module => $"{module.Name,-40} {module.Assembly.GetName().Version}");
Console.WriteLine(string.Join(Environment.NewLine, result));
Outcome: (may vary)
mscorlib.dll 4.0.0.0
WFA_Junk_4.exe 1.0.0.0
System.Windows.Forms.dll 4.0.0.0
System.dll 4.0.0.0
System.Drawing.dll 4.0.0.0
System.Configuration.dll 4.0.0.0
System.Core.dll 4.0.0.0
System.Xml.dll 4.0.0.0
However, I doubt if you really want all these System...
dlls; you, probably, want to check Assembly.GetEntryAssembly()
which is exe file or alike.
Upvotes: 4