2017-08-22 9 views
0
public class AV 
{ 
    System.Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; 

    public string currentVersion() 
    { 
     string VersionLabel = "Version: " + version.Major + "." + version.Minor + " " + BuildDate().ToShortDateString(); 
     return VersionLabel; 
    } 

    public DateTime BuildDate() 
    { 
     try 
     { 
      DateTime date = Convert.ToDateTime("8/1/2017"); 
      System.Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; 
      date = date.AddDays(version.Build); 
      date = date.AddSeconds(version.Revision * 2); 
      if (TimeZone.IsDaylightSavingTime(System.DateTime.Now, TimeZone.CurrentTimeZone.GetDaylightChanges(System.DateTime.Now.Year))) 
      { 
       date = date.AddHours(1); 
      } 
      return date; 
     } 
     catch (Exception ex) 
     { 
      return DateTime.Now; 
     } 
    } 
} 

をテストするとき、私はHTMLでこのモデルクラスを使用し、今そのはちょうど私が公開した回数だけで日付を表示し、現在のバージョンバージョン私のコードの生産にして公開または

を呼んでいます。それはビルドの日付を取得していません。ビジュアルスタジオで何かを有効にする必要があるか、何かを追加する必要がありますか?

ありがとうございました。

答えて

0

私は、現在のビルド日付を取得するには、このコードを使用します。

var version = typeof(MyApplicationName.MvcApplication).Assembly.GetName().Version; 
var buildDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond *2 * version.Revision)); 

このコードは、私のMVCアプリで動作します。私はそれがあなたにいくらか助けを与えることを願っていますメモ上記のコードのMyApplicationNameは、アプリケーションの名前です。

関連する問題