none
Why are my compile date and compile time values wrong? RRS feed

  • Question

  • In AssemblyInfo.vb I have

    <

    Assembly: AssemblyVersion("1.0.*")>

    <

    Assembly: AssemblyFileVersion("1.0.*")>

    and in my code I have

    Dim ver As Version = Assembly.GetExecutingAssembly().GetName.Version
            Dim CompileDateTime As DateTime = New DateTime(2000, 1, 1).AddDays(ver.Build).AddSeconds(ver.MinorRevision * 2)
    
            MsgBox("Compile date time is: " & CompileDateTime.ToString)

    but the date comes out as 8/23 when it should be 8/24 and the time comes out as 9:16am when it should be 10:48pm. 

    I think that I am using the standard way to get compile date and time.

    Thanks,  Bob

    Saturday, August 25, 2012 3:11 AM

Answers

  • I tried to keep the fix simple, but I guess it didn't work.  Try this instead

    Dim CompileDateTime As DateTime = _
       New DateTime(2000, 1, 1).AddDays(CType(ver.Build, Integer) And &HFFFF) _
       .AddSeconds((CType(ver.MinorRevision, Integer) And &HFFFF) * 2)

    In Visual Studio the automatic increment property is in the following menu

    Project - Properies - Publish - Publish version.

    You need to compile using Publish for the Major and Minor version to change automatically.


    jdweng

    • Proposed as answer by Mike FengModerator Tuesday, August 28, 2012 2:01 PM
    • Marked as answer by eBob.com Friday, August 31, 2012 7:54 PM
    Monday, August 27, 2012 7:00 AM
  • Thanks Joel.  The answer I needed is that it takes a Publish to increment the numbers. 

    But you are right, it's necessary to compensate for the fact that MinorRevision is a short rather than a ushort. 

    Thanks!  Bob

    • Marked as answer by eBob.com Friday, August 31, 2012 7:54 PM
    Friday, August 31, 2012 7:54 PM

All replies

  • The code is working on my computer properly.  Add "ver" to a watch window or hover over the variable while the code is running and check what the value of ver.Build and ver.MinorRevision is equal to.  I think you are assuming these numbers are correct.

    jdweng

    Saturday, August 25, 2012 11:15 AM
  • Hi Joel,

    Thanks for your interest.

    Here's my entire Load event handler:

     Dim ver As Version = Assembly.GetExecutingAssembly().GetName.Version
            Dim CompileDateTime As DateTime = New DateTime(2000, 1, 1).AddDays(ver.Build).AddSeconds(ver.MinorRevision * 2)
    
            MsgBox("Compile date time is: " & CompileDateTime.ToString)

    So there is really no opportunity for it to mess up the values.  Here's what Watch shows for ver:

    		Build	4619	Integer
    		Major	1	Integer
    		MajorRevision	0	Short
    		Minor	0	Integer
    		MinorRevision	-26514	Short
    		Revision	39022	Integer
    

    But I have no idea what Build and MinorRevision should be. It sure looks strange to me that MinorRevision is negative.

    I've learned that I get the same date and time value regardless of whether I am running under the debugger or running from the Release directory (i.e. invoking the exe directly from the Release directory).

    This is .Net 4, and Win7x64.

    Any idea what might be going on?

    Thanks,  Bob

    Saturday, August 25, 2012 2:20 PM
  • Two things ...

    1) I should have said above that I am using VBE 2010.  (I get an "unexpected error" when I try to edit the note above.)

    2) I did something this morning (but am not sure what) so that now I get todays date and a recent (although still incorrect and growing more incorrect as time pases - always 9:47:18am) time value.  It's like there is something explicit you have to do to get the Build and MinorRevision updated.

    Bob

    Saturday, August 25, 2012 3:02 PM
  • the minor revision is negative because it is a short and being converted to a long and the sign bit is being extened.  So if is really 0x968E but is bing converted to 0xFFFF968E.  So if you convert 0x968E back to decimal is is 39022.

    Now time doesn't like a negative number doesn't make much sense to the Net library.  See if this code helps explain the problem

    Sub Main()
            Dim Build As Integer = 1
            Dim Minor As Integer = 39022
            Dim CompileDateTime As DateTime = New DateTime(2000, 1, 1).AddDays(Build).AddSeconds(Minor * 2)
            MsgBox("Compile date time is: " & CompileDateTime.ToString)
            Dim shortminor = &HFFFF986E
            Minor = shortminor
            CompileDateTime = New DateTime(2000, 1, 1).AddDays(Build).AddSeconds(Minor * 2)
            MsgBox("Compile date time is: " & CompileDateTime.ToString)
            shortminor = &HFFFF986E
            Minor = shortminor And &HFFFF
            CompileDateTime = New DateTime(2000, 1, 1).AddDays(Build).AddSeconds(Minor * 2)
            MsgBox("Compile date time is: " & CompileDateTime.ToString)


    jdweng

    Saturday, August 25, 2012 3:11 PM
  • Sorry Joel, I should have added to my earlier note that once I did whatever I did this morning I no longer get any negative values:

    -  ver {1.3.4620.17619} System.Version
        Build 4620 Integer
        Major 1 Integer
        MajorRevision 0 Short
        Minor 3 Integer
        MinorRevision 17619 Short
        Revision 17619 Integer
      CompileDateTime #8/25/2012 9:47:18 AM# Date

    Saturday, August 25, 2012 3:58 PM
  • The cause of the problem is due to MajorRevision and  MinorRevision  as declared as short instead of ushort.  You can fix your code by changing the following :

    From : Dim CompileDateTime As DateTime = _
       New DateTime(2000, 1, 1).AddDays(CType(ver.Build, UShort)) _

       .AddSeconds(CType(ver.MinorRevision,UShort) * 2)

    The number -1  in the computer is stored as follows

    short - 1 = FFFE   (16 bits)

    int -1 = FFFFFE    (32 bits)

    changing the revison to 17616 (44D3) the msb bit is a zero which makes the number postivie instead of 39022 (986E) which is negative.  The first hex digit 4 is < 8 which is positive, instead of the first hex digit being 9 which is >= 8.

    When the micro-code converts a shor to an integer it must use what is called "sign extension".  tjhe most significant bit in a number is the most significant bit which is 8000 (16 bit) and 80000000 (32 bit).  When yo uconvert a short to an int the micro-code check when the most significant bit and put the bit in all the places to the left.

    So the micro code will do the following

    for the number +1 : 0001 (16 bit) = 00000001 (32 bit)

    for the number -1 :  FFFE (16 bit) =  FFFFFFFE (32 bit) 

    If sign extension wasn't used then  FFFE would become 0000FFFE which equals 65,534.

    Note : When you use a ushort instead of short then sign extension isn't used.

    Here is another example of how to prperly use a USHORT

    'Dim number1 As Short = 33902  this creates an error
    Dim number2 As UShort = 33902

    Dim number3 As UShort = CType(number2, UShort)


    jdweng

    Sunday, August 26, 2012 1:42 AM
  • Thanks for hanging in there with me Joel.  I typed in your statement exactly as it is in your note but still get the wrong result.  I think that the most significant symptom of my problem is that the date and time do not change when (I think) they should.  I think that every time I do a Build I should get new values.  But I don't.  I guess I don't care about whether Debug > Start Debugging increments the values.  Do you know when Build and MinorRevision are supposed to increment?

    Thanks,  Bob

    Sunday, August 26, 2012 1:19 PM
  • I tried to keep the fix simple, but I guess it didn't work.  Try this instead

    Dim CompileDateTime As DateTime = _
       New DateTime(2000, 1, 1).AddDays(CType(ver.Build, Integer) And &HFFFF) _
       .AddSeconds((CType(ver.MinorRevision, Integer) And &HFFFF) * 2)

    In Visual Studio the automatic increment property is in the following menu

    Project - Properies - Publish - Publish version.

    You need to compile using Publish for the Major and Minor version to change automatically.


    jdweng

    • Proposed as answer by Mike FengModerator Tuesday, August 28, 2012 2:01 PM
    • Marked as answer by eBob.com Friday, August 31, 2012 7:54 PM
    Monday, August 27, 2012 7:00 AM
  • Thanks Joel.  The answer I needed is that it takes a Publish to increment the numbers. 

    But you are right, it's necessary to compensate for the fact that MinorRevision is a short rather than a ushort. 

    Thanks!  Bob

    • Marked as answer by eBob.com Friday, August 31, 2012 7:54 PM
    Friday, August 31, 2012 7:54 PM