当前位置:  开发笔记 > 后端 > 正文

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

如何解决《ASP.NET-在屏幕底部显示应用程序构建日期/信息》经验,为你挑选了4个好方法。



1> Jørn Jensen..:

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

lblVersion.Text = String.Format("Version: {0}
Dated: {1}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(), System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly().Location).ToShortDateString());



2> g ...:

我们正在使用.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文件.

    
        
            
            
            
            
        
        
            
            
            
            ...
        
    



3> 小智..:

我正在使用.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.
// 
//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;

}



4> CMS..:

您可以通过反射获得Assembly Build日期,请查看以下示例:

艰难地确定构建日期

确定程序集的构建日期

推荐阅读
携手相约幸福
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有