This is a CodeBit that facilitates retrieval of a .NET assembly's metadata. It works in .NET Framework and .NET Core.
Download AssemblyMetadata.cs and add it to your project.
Use one of the two constructors to create an AssemblyMetadata instance. Many web tutorials and StackOverflow posts recommend calling GetExecutingAssembly(), GetCallingAssembly(), or GetEntryAssembly(). But, depending on circumstances, they may not return the assembly you want or expect. And, depending on circumstances, GetEntryAssembly()
may not work.
Instead, choose a class that belongs to the assembly for which you want information. When reporting the version number of the application, I use the Program
class like this:
var appMetadata = new AssemblyMetadata(typeof(Program));
Console.WriteLine(appMetadata.Summary);
- Make this a real unit test that compares the retrieved metadata values against the expected values.
- Access .NET Core attributes such as
Project URL
,Repository URL
,Tags
,Release Notes
and so forth.