473,473 Members | 1,576 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Date and time of compilation into string.

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__;
Nov 17 '05 #1
3 2770
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
"Jesper" wrote:
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__;

Nov 17 '05 #2
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...

--
Vadym Stetsyak aka Vadmyst
http://vadmyst.blogspot.com
"Jesper" <Je****@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
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__;

Nov 17 '05 #3
Jesper <Je****@discussions.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Michael A. Covington | last post by:
Is there a way to make a C# program print the date on which it was compiled? Finding the file date of the executable is one way, but it's not foolproof. Thanks!
7
by: James P. | last post by:
Hello there, In my asp.net page using VB, I have a date text field in mm/dd/yyyy format. When a date is entered, I'd like to validate it to make sure the date is greater than or equal to the...
28
by: richardlang | last post by:
Anyone out there ever come across a preprocessor macro that compares an argument value against the predefined __DATE__ macro in order to control conditional compilation based on date. Something...
8
by: Yaniv | last post by:
Hi I would like to add form with version data like version number and compilation time and date. I would like the time and date to be added automatically to my project. How can I do that?...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.