S
Steve Barnett
I'm trying to put together a class that retrieves version information from
my assembly and am having a problem. The code below happily retrieves the
AssemblyTitle and AssemblyDescription but fails to retrieve the Version
number. Both of these are specified in the AssemblyInfo.cs file, so I can't
see why I can't get the version umber. Any suggestions?
Thanks
Steve
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace Lucidus.IPM.IPM
{
class VersionInformation
{
public static string ProductDescription()
{
Assembly currentAssembly = Assembly.GetExecutingAssembly();
Type attrType = typeof(AssemblyDescriptionAttribute);
object[] attrs = currentAssembly.GetCustomAttributes(attrType,
false);
if (attrs.Length > 0)
{
AssemblyDescriptionAttribute desc =
(AssemblyDescriptionAttribute)attrs[0];
return desc.Description;
}
else
{
return "";
}
}
public static string ProductVersion()
{
Assembly currentAssembly = Assembly.GetExecutingAssembly();
Type attrType = typeof(AssemblyVersionAttribute);
// ***********************Always fails to get version
object[] attrs = currentAssembly.GetCustomAttributes(attrType,
false);
if (attrs.Length > 0)
{
AssemblyVersionAttribute desc =
(AssemblyVersionAttribute)attrs[0];
return desc.Version;
}
else
{
return "0.0";
}
}
public static string ProductName()
{
Assembly currentAssembly = Assembly.GetExecutingAssembly();
Type attrType = typeof(AssemblyProductAttribute);
object[] attrs = currentAssembly.GetCustomAttributes(attrType,
false);
if (attrs.Length > 0)
{
AssemblyProductAttribute desc =
(AssemblyProductAttribute)attrs[0];
return desc.Product;
}
else
{
return "";
}
}
public static string ProductTitle()
{
Assembly currentAssembly = Assembly.GetExecutingAssembly();
Type attrType = typeof(AssemblyTitleAttribute);
object[] attrs = currentAssembly.GetCustomAttributes(attrType,
false);
if (attrs.Length > 0)
{
AssemblyTitleAttribute desc =
(AssemblyTitleAttribute)attrs[0];
return desc.Title;
}
else
{
return "";
}
}
public static string ProductId()
{
Assembly currentAssembly = Assembly.GetExecutingAssembly();
string prodId = ProductTitle() + " Version " + ProductVersion();
System.Windows.Forms.MessageBox.Show(prodId);
return prodId;
}
}
}
my assembly and am having a problem. The code below happily retrieves the
AssemblyTitle and AssemblyDescription but fails to retrieve the Version
number. Both of these are specified in the AssemblyInfo.cs file, so I can't
see why I can't get the version umber. Any suggestions?
Thanks
Steve
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
namespace Lucidus.IPM.IPM
{
class VersionInformation
{
public static string ProductDescription()
{
Assembly currentAssembly = Assembly.GetExecutingAssembly();
Type attrType = typeof(AssemblyDescriptionAttribute);
object[] attrs = currentAssembly.GetCustomAttributes(attrType,
false);
if (attrs.Length > 0)
{
AssemblyDescriptionAttribute desc =
(AssemblyDescriptionAttribute)attrs[0];
return desc.Description;
}
else
{
return "";
}
}
public static string ProductVersion()
{
Assembly currentAssembly = Assembly.GetExecutingAssembly();
Type attrType = typeof(AssemblyVersionAttribute);
// ***********************Always fails to get version
object[] attrs = currentAssembly.GetCustomAttributes(attrType,
false);
if (attrs.Length > 0)
{
AssemblyVersionAttribute desc =
(AssemblyVersionAttribute)attrs[0];
return desc.Version;
}
else
{
return "0.0";
}
}
public static string ProductName()
{
Assembly currentAssembly = Assembly.GetExecutingAssembly();
Type attrType = typeof(AssemblyProductAttribute);
object[] attrs = currentAssembly.GetCustomAttributes(attrType,
false);
if (attrs.Length > 0)
{
AssemblyProductAttribute desc =
(AssemblyProductAttribute)attrs[0];
return desc.Product;
}
else
{
return "";
}
}
public static string ProductTitle()
{
Assembly currentAssembly = Assembly.GetExecutingAssembly();
Type attrType = typeof(AssemblyTitleAttribute);
object[] attrs = currentAssembly.GetCustomAttributes(attrType,
false);
if (attrs.Length > 0)
{
AssemblyTitleAttribute desc =
(AssemblyTitleAttribute)attrs[0];
return desc.Title;
}
else
{
return "";
}
}
public static string ProductId()
{
Assembly currentAssembly = Assembly.GetExecutingAssembly();
string prodId = ProductTitle() + " Version " + ProductVersion();
System.Windows.Forms.MessageBox.Show(prodId);
return prodId;
}
}
}