我需要以编程方式获取我的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;
}
Run Code Online (Sandbox Code Playgroud)