30

ネットワーク内のさまざまな顧客サーバーに多数のバージョンが展開されているasp.net Webアプリケーションがあります。問題が発生した場合、クライアントにスクリーンショットをメールで送信するという方法があります。

asp.net 1.1 の古い時代には、リフレクションを使用してビルド DLL の詳細を取得し、画面上の微妙な場所にビルド日付と番号付けに関する情報を表示することができました。

.NET 2.0 以降では、ビルド モデルが変更され、このメカニズムは機能しなくなりました。さまざまなビルド システムについて聞いたことがありますが、この機能がフレームワーク 1.1 で行ったことを、3.5 フレームワークで行う最も簡単な方法を実際に探しています。

  1. ビルドが実行されるたびに、ビルドの日付/時刻を更新し、何らかの方法でビルド番号を更新します
  2. ビルドのタイムスタンプと番号を確認して、画面に表示できるようにする
  3. 実装ができるだけ簡単であること
4

4 に答える 4

18

.Net 2.0 を使用しており、アセンブリからバージョン情報を取得しています。理想的ではないかもしれませんが、説明を使用してビルド日を保存します。

Assembly assembly = Assembly.GetExecutingAssembly();
string version = assembly.GetName().Version.ToString();
string buildDate = ((AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(
    assembly, typeof(AssemblyDescriptionAttribute))).Description;

ビルド プロセスは asminfo nant タスクを使用して、この情報を含む AssemblyInfo.cs ファイルを生成します。

    <asminfo output="Properties\AssemblyInfo.cs" language="CSharp">
        <imports>
            <import namespace="System" />
            <import namespace="System.Reflection" />
            <import namespace="System.Runtime.CompilerServices" />
            <import namespace="System.Runtime.InteropServices" />
        </imports>
        <attributes>
            <attribute type="AssemblyVersionAttribute" value="${assembly.version}" />
            <attribute type="AssemblyInformationalVersionAttribute" value="${assembly.version}" />
            <attribute type="AssemblyDescriptionAttribute" value="${datetime::now()}" />
            ...
        </attributes>
    </asminfo>
于 2008-11-27T17:16:56.667 に答える
18

私は .NET 2.0 と 3.5 を使用していますが、ビルド番号とビルド日付の両方を設定できます。ヘルプ パネルには、まだ .NET に設定させる場合、リビジョンに乱数が使用されると書かれていますが、これは正しくありません。実際には、簡単に抽出できる日付/時刻情報を配置します。これは、オンライン ドキュメントで確認できます。 : http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.assemblyversionattribute.aspx

このブログを参照してください: http://dotnetfreak.co.uk/blog/archive/2004/07/08/determining-the-build-date-of-an-assembly.aspx?CommentPosted=true#commentmessage

ビルド バージョンを自分で設定したいが、自動日付/タイム スタンプが必要なため、AssemblyVersion("1.0.*") に次のようなものを使用します。

ビルドの日付/時刻を抽出するサンプル関数を次に示します。

private System.DateTime BuildDate()
{

//This ONLY works if the assembly was built using VS.NET and the assembly version attribute is set to something like the below. The asterisk (*) is the important part, as if present, VS.NET generates both the build and revision numbers automatically.
//<Assembly: AssemblyVersion("1.0.*")> 
//Note for app the version is set by opening the 'My Project' file and clicking on the 'assembly information' button. 
//An alternative method is to simply read the last time the file was written, using something similar to:
//Return System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly.Location)

//Build dates start from 01/01/2000

System.DateTime result = DateTime.Parse("1/1/2000");

//Retrieve the version information from the assembly from which this code is being executed

System.Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

//Add the number of days (build)

result = result.AddDays(version.Build);

//Add the number of seconds since midnight (revision) multiplied by 2

result = result.AddSeconds(version.Revision * 2);

//If we're currently in daylight saving time add an extra hour

if (TimeZone.IsDaylightSavingTime(System.DateTime.Now, TimeZone.CurrentTimeZone.GetDaylightChanges(System.DateTime.Now.Year)))
{
    result = result.AddHours(1);
}

return result;

}
于 2008-12-19T18:31:34.757 に答える
7

リフレクションを通じてアセンブリビルドの日付を取得できます。次の例を確認してください。

于 2008-11-27T17:15:58.230 に答える