How to determine the assembly version of an executable?

One of my actions builds a C# .NET CF application.

In the AssemblyInfo.cs file is the following statement:

  [assembly: AssemblyVersion("0.5.*")]

In this way the buildnumber and revisionnumber will be determined by Visual Studio and will be different with each build.

How can I determine in FinalBuilder what assembly version number my executable got?

I want to use the complete version number for the filename of my setup.

 

Hi Hans

This powershell script might do what you want, although my recommendation would be to update the AssemblyInfo.cs file from FinalBuilder rather than the other way around.


# Define the assembly we want to load - a random reference assembly from SDK 3.0
$Pshfile = "C:\myassembl.dll"

# Now load the assembly
$Myasm = [System.Reflection.Assembly]::Loadfile($Pshfile)

# Get name, version and display the results
$Aname = $Myasm.GetName()
$Aver = $Aname.version

# display results
$FBVariables["MYFBVARIABLE"] = $Aver

HTH

 

 

Thanks for your example, Vincent.

I've downloaded and installed Windows Powershell.

I get an error message with your example, so I changed it to the following:

{
# Define the assembly we want to load
$FileName = "%ProjectOutputDir%\%ProjectName%.exe"

# Load the assembly
$Assembly = [System.Reflection.Assembly]::Loadfile($FileName)

# Get version
$Version = $Assembly.GetName().Version

# Store version in a Finalbuilder variable
$FBVariables.SetVariable ("ProjectFullVersion") = $Version
}

But now I get the following error message:

  Unexpected token '(' in expression or statement.
  At line:12 char:27
  + $FBVariables.SetVariable (" <<<< ProjectFullVersion") = $Version

Any ideas?

 

I'm using an AssemblyUpdater action to set the assembly version to %ProjectMajorVersionNumber%.%ProjectMinorVersionNumber%.*

Finally I would like to set the revisionnumber and buildnumber directly via Finalbuilder, but with the same calculation as happens in Visual Studio. So the build number should be the number of days after 1-1-2000 and the revision number should be number of seconds since midnight, divided by 2. But I don't know yet how to calculate those values in Finalbuilder....

 

Hi Hans

You have the wrong syntax :

$FBVariables.SetVariable(“ProjectFullVersion”,$Version)

or

$FBVariables[“ProjectFullVersion”] = $Version

As for the calculations, that could probably be done with some Script as well. I’ll add this to our todo list to add as an action or script functions.


HTH

The error Powershell gives, is related to the opening parenthesis after $FBVariables.SetVariable ("ProjectFullVersion", $Version).

I'm still stuck...

Nice that you want to add this functionality to your todo list :-)

 

ha, I found it!

I need to delete the '$' at the beginning of the line. So it becomes:

FBVariables.SetVariable ("ProjectFullVersion", $Version)

 

Well, the Powershell script did run without an error, but the ProjectFullVersion variable kept empty....I have no clue what went wrong, so I started to do it in another way. I have now a 'Run Script' action at the start of my Finalbuilder project and that works okay. Contents of that (java) script:

 var Now = new Date();
 var _1_January_2000 = new Date (2000, 0, 1);
 var NrOfMilliSecondsPerDay = 24 * 60 * 60 * 1000;
 var NrOfMinutesPerHour = 60;
 var NrOfSecondsPerMinute = 60;
 var NrOfSecondsPerHour = NrOfMinutesPerHour * NrOfSecondsPerMinute;
 
 // determine the number of days between now and 1 January 2000
 var DifferenceInMilliSeconds = Math.abs (Now.getTime() - _1_January_2000.getTime());
 var DifferenceInDays = Math.floor (DifferenceInMilliSeconds / NrOfMilliSecondsPerDay);
 
 ProjectBuildNumber = DifferenceInDays;
 
 // determine the number of seconds between now and midnight
 var DifferenceInSeconds = (Now.getHours() * NrOfSecondsPerHour) + (Now.getMinutes() * NrOfSecondsPerMinute) + (Now.getSeconds());
 
 ProjectRevisionNumber = Math.floor (DifferenceInSeconds / 2);