开发者

How can I update a setting based on the build?

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:

  1. Use a build script to change a DateTime setting whenever the application is built.

  2. Get the latest modification time o开发者_C百科f all files in the application folder

What approach seems more interesting? Do you have any suggestion?


  1. 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.

  2. 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)

  3. 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):

AssemblyName an = Assembly.GetEntryAssembly().GetName();
DateTime date = new DateTime(2000, 1, 1, 0, 0, 0);
date += TimeSpan.FromDays(an.Version.Build) + TimeSpan.FromSeconds(an.Version.Revision * 2);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜