我有一個程序,我已經寫了,並正在嘗試創建一個關於框。我最近將程序的產品版本更新爲1.00.0003,我希望將其反映在關於窗口的窗口中。如何以編程方式使用C#獲取正在運行的程序的產品(不是裝配)版本?
的AboutBox的的缺省設置顯示的一個1.0.0.0值,這是組件版本,而不是產品版本。我一直在淘網上找到如何獲得產品版本。我已經嘗試了所有的這些:
{
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fileVersionInfo.ProductVersion;
Debug.WriteLine(version);
Debug.WriteLine(assembly.GetName().Version);
string v = VersionNumber;
Debug.WriteLine(v);
Debug.WriteLine(fileVersionInfo.FileVersion);
Debug.WriteLine(Application.ProductVersion);
Debug.WriteLine(AssemblyProductVersion);
Assembly assembly2 = Assembly.GetEntryAssembly();
FileVersionInfo fileVersionInfo2 = FileVersionInfo.GetVersionInfo(assembly.Location);
string version2 = fileVersionInfo2.ProductVersion;
Debug.WriteLine(version2);
Debug.WriteLine(assembly2.GetName().Version);
return version;
}
private string _ourVersion = "Version: v";
private string VersionNumber
{
get
{
System.Reflection.Assembly _assemblyInfo =
System.Reflection.Assembly.GetExecutingAssembly();
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
_ourVersion += ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
else
{
if (_assemblyInfo != null)
_ourVersion += _assemblyInfo.GetName().Version.ToString();
}
return _ourVersion;
}
}
private static string AssemblyProductVersion
{
get
{
object[] attributes = Assembly.GetExecutingAssembly()
.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
return attributes.Length == 0 ?
"" :
((AssemblyInformationalVersionAttribute)attributes[0]).InformationalVersion;
}
}
這些回報1.0.0.0每一個人(是的,我也期待他們在控制檯輸出,沒有什麼實際顯示),而不是1.00.0003就像我需要。產品版本在InstallShield設置的「常規信息」選項卡中設置。安裝時,轉到程序和功能顯示1.00.0003的產品版本,所以我無法弄清楚爲什麼這很難以編程方式檢索此值。有任何想法嗎?
如果設置此版本信息的第一個位置在安裝程序中,則不應指望任何編譯的文件包含此信息。顯然,正如你設置的那樣,只有安裝者知道它的版本。 – 2013-02-22 07:20:05
@Damien_The_Unbeliever如何設置它,以便如果我在安裝程序中更改版本,其他所有內容都會相應更改? – Garrett 2013-02-22 07:44:13
你正在考慮錯誤的方法。根據devdigital的回答,您應手動更新*程序集*信息並讓安裝程序*選擇該更改。 – 2013-02-22 07:48:01