Don't you just love it when you get answers explaining exactly how to do
the two things you specifically said you didn't want to do? :-)
Vladimir's solution works, and meets your requirements, but has the
unfortunate downside that you end up with a multi-module assembly, which
is less convenient than a normal one-file assembly.
What I'd do is add a pre-build step that generates a C# source file
containing the information you require.
Here's a particularly low-tech solution. I added this as a prebuild
event:
echo public class BuildTime { public const string Time = "%TIME%";
public const string Date = "%DATE%"; } > $(ProjectDir)Timestamp.cs
I then added Timestamp.cs to my project.
This seems to work with one tiny problem - the date format will be
determined by the locale of the build machine. Because my machine is
configured to know that it's in the UK, I get properly formatted dates,
where the day precedes the months. (DD/MM/YYYY) If however you were to
run it on an American machine, you would get the curious and
inexplicable MM/DD/YYYY format instead. :-)
Depending on what you wanted to do with this information, that's either
not a problem, or a big problem... If you need to control the format
independently of the build machine locale, then maybe writing a program
to spit out the source code would be better than just using ECHO...
--
Ian Griffiths
DevelopMentor
> -----Original Message-----
> From: Raj Malli
>
> Hi guys
>
> Is there a way by which I can programmatically determine the build
time of
> an assembly? I would like to show the following information in the
"About"
> box of my application: Application Name, Version and Build Time.
>
> I do not want to do the following:
> - Use the last two parts of the assembly version to encode the time
> - Get the last modified time from the assembly file using (say) the
> FileInfo class
>
> In C/C++, this is how I'd have done this:
> #define BUILD_TIME __TIME__
> void OnAbout() {
> ...
> MessageBox(BUILD_TIME);
> ...
> }
> I know C# supports a preprocessor. Can I do something similar to the
above
> in C#? Otherwise what other options do I have?
===================================
This list is hosted by DevelopMentor� http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com