How can I display build number?

  • Thread starter Thread starter Abe Frohnman
  • Start date Start date
A

Abe Frohnman

I'm wondering how I can access the version info within AssemblyInfo.cs
in my program? I'd like to output the version of my program in a text
label but I can't find any clear examples on how to do this.

Thanks!

AF
 
Some of this information is available in the Application and Environment
objects in System.Windows.Forms, but some of this information can only be
obtained by using reflection on your assembly, like this:

object[] attrs =
System.Reflection.Assembly.GetEntryAssembly().GetCustomAttributes(true);

foreach (object o in attrs)

if (o.GetType() == typeof(System.Reflection.AssemblyTitleAttribute))

programName = ((System.Reflection.AssemblyTitleAttribute)o).Title;



Chris
 
When I run this code, nothing is displayed.

Chris said:
Some of this information is available in the Application and Environment
objects in System.Windows.Forms, but some of this information can only be
obtained by using reflection on your assembly, like this:

object[] attrs =
System.Reflection.Assembly.GetEntryAssembly().GetCustomAttributes(true);

foreach (object o in attrs)

if (o.GetType() == typeof(System.Reflection.AssemblyTitleAttribute))

programName = ((System.Reflection.AssemblyTitleAttribute)o).Title;



Chris

I'm wondering how I can access the version info within AssemblyInfo.cs
in my program? I'd like to output the version of my program in a text
label but I can't find any clear examples on how to do this.

Thanks!

AF
 
This is the relevant code I have. There's a string called programName as
well.

public AboutForm()
{
InitializeComponent();

object[] attrs =
System.Reflection.Assembly.GetEntryAssembly().GetCustomAttributes(true);

foreach (object o in attrs)
{

if (o.GetType() == typeof(System.Reflection.AssemblyTitleAttribute))

programName = ((System.Reflection.AssemblyTitleAttribute)o).Title;
}

Console.WriteLine("Program name is " + programName);

The only thing I can think of is that it might need to go somewhere
besides the AboutForm() constructor, but I'm not sure where else to put
it....
 
Or better yet, just use System.Windows.Forms.Environment.Version. That
avoids the function call.

Chris
 
This works, but I have two more questions:

1) Is there a way I can do this so it just gets one of the properties?
ie: just major, or minor version? Or just build instead of all four?

2) In ProjectBuilder for OS X, there's a variable that keeps track of
the build number for the project. Each time the program is compiled, the
build number is incremented by one. I was hoping to find something like
that in VS NET. Yet each time I build the program, the number stays the
same. Am I looking in the wrong place?

Thanks for the help! :)

AF
 
Does your AssemblyInfo.cs have a line that looks like this?

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

If so, the build number should increment correctly.

Chris
 
Yes, it has that line. When I build it the first time I get this for the
version: 1.0.1297.23935. The second time I get 1.0.1297.23983 when I was
expecting x.x.x.23936.
 
The revision number is based on the time of day. :-) That way you always
know the relative build times of various assemblies according to their
versions. Watch it reset at midnight. :-)

Chris

Abe Frohnman said:
Yes, it has that line. When I build it the first time I get this for the
version: 1.0.1297.23935. The second time I get 1.0.1297.23983 when I was
expecting x.x.x.23936.

Chris said:
Does your AssemblyInfo.cs have a line that looks like this?

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

If so, the build number should increment correctly.

Chris
 
Back
Top