如何获取程序集的最后修改日期?
我想渲染(用于内部调试/信息)程序集的最后修改日期,这样我就知道某个网站的部署时间。
通过反射可以得到吗?
我得到这样的版本:
Assembly.GetExecutingAssembly().GetName().Version.ToString();
我正在寻找类似的东西 - 我不想打开物理文件,获取其属性或类似的东西,因为我将在母版页中呈现它,并且不要不想要那种开销。
I want to render (for internal debugging/info) the last modified date of an assembly, so I'll know when a certain website was deployed.
Is it possible to get it through reflection?
I get the version like this:
Assembly.GetExecutingAssembly().GetName().Version.ToString();
I'm looking for something similar -- I don't want to open the physical file, get its properties, or something like that, as I'll be rendering it in the master page, and don't want that kind of overhead.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我会赞同 pYrania 的答案:
但是添加以下内容:
您提到您不想访问文件系统,因为它位于您的母版页中,并且您不想为每个页面都点击额外的文件系统。 所以不要,只需在应用程序加载事件中访问它一次,然后将其存储为应用程序级变量即可。
I'll second pYrania's answer:
But add this:
You mention you don't want to access the file system since it's in your master page and you don't want to make that extra file system hit for every page. So don't, just access it once in the Application load event and then store it as an application-level variable.
如果您在 AssemblyInfo 中默认修订版本号和内部版本号:
您可以通过以下方式获取大致的构建日期:
If you default the Revision and Build Numbers in AssemblyInfo:
You can get the an approximate build date with:
这个怎么样?
How about this?
有些人认为 Assembly 不保留构建日期,但你知道他们错了,
您可以从嵌入在可执行文件中的 PE header 检索链接器时间戳,如下所示工作(我自己没有测试过代码)
或者如果程序集是你自己的,你可以使用以下方法,简单易行,
在下面添加到预构建事件命令行:
将此文件添加为资源,现在你的文件中有“BuildDate”字符串资源。
我已经从这个问题中获取了两个答案
Some people think that Assembly doesn't holds build date but you know what they are wrong,
you can be retrieve the linker timestamp from the PE header embedded in the executable file, like following may work (i havn't tested the code myself)
or if assembly is your's own better you use following approach simple and easy
Add below to pre-build event command line:
Add this file as resource, now you have 'BuildDate' string in your resources.
I have taken both answers from this question
由于使用了
1970
的int32
,RetrieveLinkerTimestamp
解决方案在2038
之后将不再工作。 我建议使用以下内容(尽管这可能也有其局限性):The
RetrieveLinkerTimestamp
solution will not work after the year2038
due to the use ofint32
from1970
. I suggest using the following (although this probably has its limitations too):我不相信程序集保存了最后修改的信息,因为这是操作系统属性。 我相信获取此信息的唯一方法是通过文件句柄。
I don't believe the assembly holds last modified information as that is an operating system attribute. I believe the only way to get this information is through a file handle.