我需要以编程的方式获取我的Windows服务版本并将其存储在字符串中。然后,在ProjectInstaller类中,我将把版本追加到我的显示名称和服务名称中。目前,我得到了一个空字符串,而且我很难调试我的安装程序。这是我的当前代码:
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;
}
version.Major.ToString().PadLeft(10, '0') + "." + version.Minor
的东西。 - John Gietzen