I need to obtain the version of my Windows service programmatically and store it in a string. Then, I'll append the version to my display name and service name in the ProjectInstaller class. Right now I'm getting an empty string and I'm having trouble debugging my setup project. Here's my current code:
string version = null;
try
{
Assembly exeAssembly = Assembly.GetEntryAssembly();
Type attrType = typeof(AssemblyFileVersionAttribute);
object[] attributes = exeAssembly.GetCustomAttributes(attrType, false);
if (attributes.Length > 0)
{
AssemblyFileVersionAttribute verAttr = (AssemblyFileVersionAttribute)attributes[0];
if (verAttr != null)
{
version = verAttr.Version;
}
}
}
catch
{
}
if (version == null)
{
version = string.empty;
}