如何根据构建更新设置?
我开发了一个 HTTP 资源,它使用 Last-Modified
标头,它应该反映对应用程序所做的任何修改。我想更新此字段以告知构建日期或上次应用程序更新日期。以下是我想到的一些解决方案:
每当构建应用程序时,使用构建脚本更改日期时间设置。
获取应用程序文件夹中所有文件的最新修改时间
什么方法看起来更有趣?您有什么建议吗?
I have developed a HTTP resource, that uses the Last-Modified
header, and it should reflect any modifications made to the application. I would like to update this field to tell the build date, or the last application update date. Here is some solutions I have thought of:
Use a build script to change a DateTime setting whenever the application is built.
Get the latest modification time of all files in the application folder
What approach seems more interesting? Do you have any suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非常容易做到。您可以编写一个简单的文件(例如 xml)并将其添加为嵌入式资源,以便将其编译到您的应用程序中。这使您可以自由地提供您需要的任何形式的信息。
我会避免这种情况。这有点hacky,并且容易出现问题(例如,如果将日志文件写入文件夹,那么您将开始报告今天的日期而不是构建日期)。更好更容易地从 Application.StartupPath(即主 .exe 文件)读取日期戳
在 AssemblyInfo 中,指定
[ assembly: AssemblyVersion("1.23.*")] 的版本
编译器会自动将构建日期和时间添加到版本中(看起来有点像:1.23.4567.12345)。然后,您可以使用以下方法读取编译的日期/时间(从搜索命中中捏出,但看起来大致正确):Is very easy to do. You can write out a simple file (e.g. xml) and add it as an embedded resource so it's compiled into your app. THis gives you the freedom of it providing any form of information you require.
I'd avoid this. It's a bit hacky, and prone to problems (e.g. if a log file is written to the folder, then you'll start reporting today's date instead of the build date). Better and easier to just read the datestamp from Application.StartupPath (i.e. the main .exe file)
In your AssemblyInfo, specify a version of
[assembly: AssemblyVersion("1.23.*")]
and the compiler will automatically add the build date and time to the version (it'll look a bit like: 1.23.4567.12345). You can then read the date/time of compilation out using (pinched from a search hit, but looks about right):