Date and time of compilation into string.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

In c++ ( I do no longer remember exactly how) I used some compiler
predefined macro to insert the date and time of compilation into a string.
How is this done in c#

In c++ it could have looked something like this

wchar_t *ptr= __DATE__;
 
Unfortunately C# lacks macros like what C/C++ support and the .NET framework
does not provide any kind of mechanism like what you are looking for.

You still have a couple of options... use a * for the second half of your
application version number so as to have the compiler generate a new and
unique version # each time the app is built based on the date and time.

Otherwise you could just look at the last modified attribute on the file
itself.

Brendan
 
You can do this with the help of attributes.
In VC++ the enviromnent ( compiler ) specified __DATE__ and __TIME__, that
is why in the compiled source was required data.

I see 2 ways how can you achieve same result
1) write attribute class that will hold the date. The targe of this
attribute will be the assembly you're building ( watch for AssemblyInfo.cs,
when using wizard ). Minus of this way is that you'll have to specify
manually build date.

2) You can use CompilerServices. You generate source code that will contain
the applied attribute with correct date value. CompilerServices will let you
build your assembly manually thus you will mimic the behavior of the C++
compiler...
 
Jesper said:
In c++ ( I do no longer remember exactly how) I used some compiler
predefined macro to insert the date and time of compilation into a string.
How is this done in c#

In c++ it could have looked something like this

wchar_t *ptr= __DATE__;

You can't do this in C#, I'm afraid. In theory you could load the
assembly file and find the linking date and time from that.
Alternatively, you could write a pre-build step which generated a
resource for inclusion into the assembly with the current date and
time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top