【C#】Assembly ( アセンブリ )

Assembly ( アセンブリ )について

 * [Propeties]-[AssemblyInfo.cs]に、バージョン名などのシステム情報が格納されている

Assembly情報の編集

 * [Propeties]をクリックし、[アプリケーション]-[アセンブリ情報]ボタンをクリックし、編集できる

Assembly情報の取得

アセンブリの表示名

* プロジェクト名を右クリックし、[アプリケーション]タブで、「アセンブリ名」などのパラメータを表示
string assemblyName = Assembly.GetCallingAssembly().FullName;

バージョン名

string version = Application.ProductVersion;

製品名

string productName = Application.ProductName;

会社名

string companyName = Application.CompanyName;

コピーライト

* 一見、難しそうに書いてあるが、一つ覚えれば、商標も詳細情報もほぼ同じ。
string copyright = string.Empty;
object[] copyrights = Assembly.GetEntryAssembly().GetCustomAttributes(
      typeof(AssemblyCopyrightAttribute), false);
if ((copyrights != null) && (copyrights.Length > 0))
{
    copyright = ((AssemblyCopyrightAttribute)copyrights[0]).Copyright;
}

商標

string trademark = string.Empty;
object[] trademarks = Assembly.GetEntryAssembly().GetCustomAttributes(
    typeof(AssemblyTrademarkAttribute), false);
if ((trademarks != null) && (trademarks.Length > 0))
{
    trademark = ((AssemblyTrademarkAttribute)trademarks[0]).Trademark;
}

詳細情報(説明)

string description = string.Empty;
object[] descriptions = Assembly.GetEntryAssembly().GetCustomAttributes(
    typeof(AssemblyDescriptionAttribute), false);
if ((descriptions != null) && (descriptions.Length > 0))
{
    description = ((AssemblyDescriptionAttribute)descriptions[0]).Description;
}