If the assembly name, version and culture are the only concern for us, we do not have to bother to use the Assembly.GetCustomAttributes() method.
In fact, it does not work for us most likely due to the fact that these most common attributes are not custom at all! But the AssemblyName is exactly what we are looking for.
The AssemblyName is not a string type as most of people may imagine. It contains quite some useful information, e.g. the assembly name, version and culture that we are interested in here.
Here are some code snippets to retrieve the information:
…
MessageBox.Show(ShortcutsOfAssemblyInfo(Assembly.GetExecutingAssembly()));
…
static public string ShortcutsOfAssemblyInfo(Assembly asm)
{
string info = string.Empty;
AssemblyName asmName = asm.GetName();
info = String.Format("Assembly Name: {0}\nAssembly Version: {1}\nAssembly Culture: {2}", asmName.Name, asmName.Version, asmName.CultureInfo.NativeName);
return info;
}
These information can be displayed in an About dialog to give your customers a general idea about your programs, e.g. what the product is, which exact version it is, and what culture it supports the best.
AssemblyInfo Updater of RevitAddinWidget can help review popular assembly attributes of all available projects in a Visual Studio solution and update the information conveniently and flexibly in a single central place.
Recent Comments