How do I obtain the version information for my Windows Service programmatically

Posted by user302004 on Stack Overflow See other posts from Stack Overflow or by user302004
Published on 2010-06-10T17:40:24Z Indexed on 2010/06/10 17:42 UTC
Read the original article Hit count: 232

Filed under:
|

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; }

© Stack Overflow or respective owner

Related posts about c#

Related posts about setup-project