首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ASP.NET -在屏幕底部显示应用程序构建日期/信息

问ASP.NET -在屏幕底部显示应用程序构建日期/信息
EN

Stack Overflow用户
提问于 2008-11-27 17:04:09
回答 4查看 29.7K关注 0票数 32

我有一个asp.net web应用程序,它在其网络中的不同客户服务器上部署了许多版本。我们的一个做法是让客户在遇到问题时用电子邮件截图。

在旧的asp.net 1.1天中,我们可以使用反射获取构建DLL的细节,并在一个微妙的位置显示有关构建日期和屏幕编号的信息。

在使用.NET 2.0和更高版本时,构建模型发生了变化,这种机制不再起作用。我听说过不同的构建系统,但是我真的在寻找最简单的方法,在3.5框架上完成这个功能在Framework1.1上所做的工作。

  1. 每次执行构建时,更新构建日期/时间,并以某种方式更新生成号。
  2. 能够看到构建时间戳和数字,并在屏幕上显示。
  3. 尽可能简单地实现
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2008-11-27 17:16:56

我们正在使用.Net 2.0并将版本信息从程序集中提取出来。也许并不理想,但我们使用描述来存储构建日期。

代码语言:javascript
复制
Assembly assembly = Assembly.GetExecutingAssembly();
string version = assembly.GetName().Version.ToString();
string buildDate = ((AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(
    assembly, typeof(AssemblyDescriptionAttribute))).Description;

构建过程使用asminfo nant任务生成包含此信息的AssemblyInfo.cs文件。

代码语言:javascript
复制
    <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>
票数 18
EN

Stack Overflow用户

发布于 2009-03-24 13:30:38

我选择只使用执行程序集的日期。就我发布文件的方式来说,这很好。

代码语言:javascript
复制
lblVersion.Text = String.Format("Version: {0}<br>Dated: {1}",
    System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),
    System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly().Location).ToShortDateString());
票数 43
EN

Stack Overflow用户

发布于 2008-12-19 18:31:34

我使用的是.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.*")中使用了类似的内容

下面是一个提取构建日期/时间的示例函数

代码语言:javascript
复制
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;

}
票数 18
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/324245

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档