Assembly

De Banane Atomic
Aller à la navigationAller à la recherche

Ordre de chargement

  1. GAC
  2. Codebases
  3. Application's root directory
    1. No culture information
      1. [application base] / [assembly name].dll
      2. [application base] / [assembly name] / [assembly name].dll
    2. Culture information is specified for the referenced assembly
      1. [application base] / [culture] / [assembly name].dll
      2. [application base] / [culture] / [assembly name] / [assembly name].dll
  4. Private binpath (sous dossier de Application's root directory)
    1. No culture information
      1. [application base] / [binpath] / [assembly name].dll
      2. [application base] / [binpath] / [assembly name] / [assembly name].dll
    2. Culture information is specified for the referenced assembly
      1. [application base] / [binpath] / [culture] / [assembly name].dll
      2. [application base] / [binpath] / [culture] / [assembly name] / [assembly name].dll

Obtenir la version

Csharp.svg
Assembly.GetEntryAssembly().GetName().Version.ToString();
Powershell.png
[Reflection.AssemblyName]::GetAssemblyName('MonAssembly.dll').Version

Assembly vs File vs Product version

  • If Assembly version is not explictly specified, it takes the value of 0.0.0.0.
  • If File version is not explicitly specified, it takes the value of Assembly version.
  • If Product version is not explicitly specified, it takes the value of File version.

Assembly

Csharp.svg
// L'exécutable
Assembly entryAssembly = Assembly.GetEntryAssembly();
// L'assemblage en cours d'exécution
Assembly executingAssembly = Assembly.GetExecutingAssembly();
// L'assemblage ayant appelé la méthode en cours d'exécution
Assembly callingAssembly = Assembly.GetCallingAssembly();

// Charger une assembly depuis son nom
Assembly assembly = Assembly.Load("Namespace.Class, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null");
Assembly assembly = Assembly.LoadWithPartialName("Namespace.Class");

// Charger une assembly depuis un de ses types
Assembly assembly = Assembly.GetAssembly(typeof(Console));

// chemin vers le fichier *.exe
string path = Assembly.GetEntryAssembly().Location;
// chemin vers le dossier contenant le fichier *.exe
string folder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

// Version
Version assemblyVersion = Assembly.GetEntryAssembly().GetName().Version;
string stringAssemblyVersion = assemblyVersion.ToString(); // "1.0.0.0"

string fileVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
string productVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;

Attributs de l'assemblage

40px
// Description
object[] attributes = _assembly.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
if (attributes.Length != 0)
{
    string description = ((AssemblyDescriptionAttribute)attributes[0]).Description;
}

// Product
object[] attributes = _assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false);
if (attributes.Length != 0)
{
    string product = ((AssemblyProductAttribute)attributes[0]).Product;
}

// Copyright
object[] attributes = _assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
if (attributes.Length != 0)
{
    string copyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
}

// Company
object[] attributes = _assembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
if (attributes.Length != 0)
{
    string company= ((AssemblyCompanyAttribute)attributes[0]).Company;
}

// Guid
object[] attributes = _assembly.GetCustomAttributes(typeof(GuidAttribute), false);
if (attributes.Length != 0)
{
    string guid = ((GuidAttribute)attributes[0]).Value;
}

// ClientCompany
object[] attributes = _assembly.GetCustomAttributes(typeof(ClientCompanyAttribute), false);
if (attributes.Length != 0)
{
    string clientCompany= ((ClientCompanyAttribute)attributes[0]).ClientCompany;
}