Saving codes source file date-time stamp for run-time use

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

Guest

Hi,
Using C# and VS.net.
During the compilation of a class, I would like to take its source file
date-time stamp and save it for later reference during run-time.
How can you get this information saved off during the build process? and of
course then get access to it?

Thanks
 
For the whole compile, you can check file attributes of the assembly either
through File or through Refelection on the assembly. For individual bits, the
/obj directory contains the individual objects.

If you want to be proactive, consider having the compile step fired off by a
harness using Reflection.Emit. You can combine individual compiled bits into
one assembly via the al.exe command line tool (assembly linker).

Those are the first two that come to mind.

---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Hi Ken,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to put the build date in the
assembly and get it programatically. If there is any misunderstanding,
please feel
free to let me know.

Gregory has provided us with two good ideas. Besides we can also use the
auto-generated version number to achieve this.

If we use <Assembly: AssemblyVersion("1.0.*")> as assembly version, VS.NET
will generate build number and revision according to the current date and
time. We can try to use the following code to get the build date.

Private Function BuildDate() As DateTime
'Build dates start from 01/01/2000
Dim result As Date = #1/1/2000#

'Retrieve the version information from the assembly from which this
code is being executed
Dim version As System.Version =
System.Reflection.Assembly.GetExecutingAssembly.GetName.Version

'Add the number of days (build)
result = result.AddDays(version.Build)

'Add the number of seconds since midnight (revision) multiplied by 2
result = result.AddSeconds(version.Revision * 2)

'If we're currently in daylight saving time add an extra hour
If TimeZone.IsDaylightSavingTime(Now,
TimeZone.CurrentTimeZone.GetDaylightChanges(Now.Year)) Then
result.AddHours(1)

Return result
End Function

For more information, please check the following link:

http://dotnetfreak.co.uk/blog/archive/2004/07/08/146.aspx
PS: There is a little mistake in the code provided in the link. I have
fixed it in my code.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi Kevin,

I am going to have many classes, all of which will be linked into one final
assembly (DLL file). I need the ability to check each of the classes source
file time-stamps independently, so the assembly's one field will not do. I
could do this by adding a field into the classes that would be human
adjusted, but this would be very prone to errors.
What I really wanted was an automatted method of updating a field every time
the source was changed. I am trying to capture source changes, I do not care
about when it was built, as I would want the same data returned even if I
built it several times without changing the source. Something like the C
compilers preprocessor macro __TIMESTAMP__.

****
Writing this has made me think a bit outside the box. I tried out
SourceSafe and found I could have it update a variable on file checkins,
which will take care of what I needed!!!!
I am still interested if I could get also achieve my goal using the compiler?
****

Thanks
 
The first does not give a fine enough resolution for what I need (see my
response to Kevin).

I am not sure I understand the second. Is this a custom build action?
And how would I get the info I need? (also see other response)

Thanks for responding.
 
Back
Top