Menü Schließen

Obtain information about the Executing Assembly

Path of the executing assembly:

public static string GetExecutingAssemblyPath()
{
  string codeBase = Assembly.GetExecutingAssembly().CodeBase;
  UriBuilder uri = new UriBuilder(codeBase);
  string path = Uri.UnescapeDataString(uri.Path);
  return Path.GetDirectoryName(path);
}

Get title of executing assembly:

/// <summary>
/// Gets the assembly title.
/// </summary>
public static string GetAssemblyTitle()
{
  object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
  if (attributes.Length > 0) {
    var titleAttribute = (AssemblyTitleAttribute)attributes[0];
    if (!string.IsNullOrWhiteSpace(titleAttribute.Title)
      return titleAttribute.Title;
  }
  return Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
}

 

Ähnliche Beiträge

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert