
為了進行版本控制 (version control), Assembly version 是其中一個決定執行檔版本的方法. 然而除了在執行檔中檢查, 可以利用Reflection 檢查檔案版本.
而版本資訊在Project Property > Application > Assembly Information… 中進行設定.
AssemblyHelper.cs
public static class AssemblyHelper { /// <summary> /// Get current assembly version. /// </summary> /// <returns></returns> public static string GetCurrentVersion() { string result = string.Empty; if (ApplicationDeployment.IsNetworkDeployed) { Version currentVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion; result = currentVersion.ToString(); } else { System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location); result = fvi.FileVersion; } return result; } }
Leave a Reply