相当于__DATE__,__TIME__宏在C# [英] Equivalent of __DATE__, __TIME__ macros in C#
本文介绍了相当于__DATE__,__TIME__宏在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
C#中是否有相当于 __ DATE __
和 __ TIME __
Is there an equivalent of __DATE__
and __TIME__
in C#?
基本上我要做的是在C#应用程序中放置一些构建时间戳。
Basically what I'm trying to do is place some build timestamping in a C# application.
一种可能性我看到微软的网站是为了执行以下操作:
One possibility I saw on Microsoft's website was to do the following:
Assembly assem = Assembly.GetExecutingAssembly();
Version vers = assem.GetName().Version;
DateTime buildDate = new DateTime(2000, 1, 1).AddDays(vers.Build).AddSeconds(vers.Revision * 2);
Console.WriteLine(vers.ToString());
Console.WriteLine(buildDate.ToString());
但是,只有在AssemblyInfo.cs中的版本为1.0。 / em>,我们将不会。
However, this only works if your version in AssemblyInfo.cs is "1.0..", which ours won't be.
推荐答案
我建议您自定义您的构建脚本,将日期时间写入文件。 MSBuild社区任务项目有一个时间任务,可以用于这个。
I recommend customising your build script to write the date time into the file. The MSBuild Community Tasks project has a Time task that can be used for exactly this.
这篇关于相当于__DATE__,__TIME__宏在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文