Visualizzazione post con etichetta Reflection. Mostra tutti i post
Visualizzazione post con etichetta Reflection. Mostra tutti i post

giovedì 9 luglio 2009

Get the version information of an extern assembly

We have more ways to get the information of an assembly, the most two I use are:
  1. Only for .NET assembly
    System.Reflection.Assembly AssemblyFileInfo = System.Reflection.Assembly.Load(FileAppPath);
    Console.WriteLine (AssemblyFileInfo.GetName().Version);

  2. For all .NET and native assembly
    FileVersionInfo AssemblyFileVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(FileAppPath);
    Console.WriteLine(AssemblyFileVersion.FileVersion)

martedì 9 giugno 2009

Application Path

Sometime I need to retrieve the application path, here I add the four methods I use frequently.

  1. The simple way through windows forms:
    using
    System.Windows.Forms;
    String sAppPath1 = Application.StartupPath;
  2. From the binary over reflection:
    String sAppPath2 = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase );
  3. Using the file informations:
    FileInfo executableFileInfo = new FileInfo (Application.ExecutablePath);
    String sAppPath3 = executableFileInfo.DirectoryName;
  4. When my program is started from another:
    System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
Happy coding.