The AssemblyConfiguration attribute is to generally specify some custom information pertinent to the assembly build type (usually DEBUG or RELEASE), but since it is just a string, we could put anything in there, actually.
We can conditionally define the AssemblyConfiguration attribute in the AssemblyInfo.cs for C# projects like this:
#if DEBUG
[assembly: AssemblyConfiguration("DEBUG")]
#else
[assembly: AssemblyConfiguration("NOT_DEBUG")]
#endif
Then we can use some code like the following to tell what build the assembly is at runtime when the AssemblyConfiguration attribute is the only concern:
…
MessageBox.Show(GetConfigurationInfo());
…
private string GetConfigurationInfo()
{
Assembly asm = Assembly.GetExecutingAssembly();
Attribute att = AssemblyConfigurationAttribute.GetCustomAttribute(asm, typeof(AssemblyConfigurationAttribute));
AssemblyConfigurationAttribute confAtt = att as AssemblyConfigurationAttribute;
return confAtt.Configuration;
}
So another way to read some assembly attributes out from an assembly is introduced here. That is, we can use the particular assembly attribute type and call its static method GetCustomAttribute() to read a particular attribute out.
You may wonder why it needs us to specify the same assembly attribute type again since it is called from the type itself.
Good question! In fact, the method is inherited from its parent, the Attribute type. As the static method is supposed to work with any attribute types, to specify the attribute type is apparently necessary. It would be better though for each concrete attribute type to provide us its signature to get its own attribute information out from the passed in assembly with the extra type parameter eliminated.
AssemblyInfo Updater of RevitAddinWidget can help review popular assembly information of all available projects in a Visual Studio solution and update the information conveniently and flexibly in a single central place.
Recent Comments