By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

How can I display build number?

P: n/a
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

Nov 15 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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().GetC ustomAttributes(true);

foreach (object o in attrs)

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

programName = ((System.Reflection.AssemblyTitleAttribute)o).Titl e;

Chris

"Abe Frohnman" <us******@SPAMexperimentzero.org> wrote in message
news:G0*********************@news.easynews.com...
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

Nov 15 '05 #2

P: n/a
When I run this code, nothing is displayed.

Chris Capel wrote:
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().GetC ustomAttributes(true);

foreach (object o in attrs)

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

programName = ((System.Reflection.AssemblyTitleAttribute)o).Titl e;

Chris

"Abe Frohnman" <us******@SPAMexperimentzero.org> wrote in message
news:G0*********************@news.easynews.com...
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



Nov 15 '05 #3

P: n/a
This is the relevant code I have. There's a string called programName as
well.

public AboutForm()
{
InitializeComponent();

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

foreach (object o in attrs)
{

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

programName = ((System.Reflection.AssemblyTitleAttribute)o).Titl e;
}

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....

Chris Capel wrote:
I don't understand. You declared a string variable "programName" and called
MessageBox.Show("Program name is " + programName); ? The build version is in
a different attribute, of course. All you have to do is change the type and
the property.

Chris


Nov 15 '05 #4

P: n/a
Or better yet, just use System.Windows.Forms.Environment.Version. That
avoids the function call.

Chris

"Ignacio Machin" <ignacio.machin AT dot.state.fl.us> wrote in message
news:uV**************@TK2MSFTNGP11.phx.gbl...
Hi,

Try : Assembly.GetExecutingAssembly().GetName.Version , that return a
Version instance, this class implement these properties:

Public Properties
Build
Supported by the .NET Compact Framework.
Gets the value of the build component of the version number for this
instance.
Major
Supported by the .NET Compact Framework.
Gets the value of the major component of the version number for this
instance.
Minor
Supported by the .NET Compact Framework.
Gets the value of the minor component of the version number for this
instance.
Revision
Supported by the .NET Compact Framework.
Gets the value of the revision component of the version number for this instance.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Abe Frohnman" <us******@SPAMexperimentzero.org> wrote in message
news:G0*********************@news.easynews.com...
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


Nov 15 '05 #5

P: n/a
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

Ignacio Machin wrote:
Hi,

Try : Assembly.GetExecutingAssembly().GetName.Version , that return a
Version instance, this class implement these properties:

Public Properties
Build
Supported by the .NET Compact Framework.
Gets the value of the build component of the version number for this
instance.
Major
Supported by the .NET Compact Framework.
Gets the value of the major component of the version number for this
instance.
Minor
Supported by the .NET Compact Framework.
Gets the value of the minor component of the version number for this
instance.
Revision
Supported by the .NET Compact Framework.
Gets the value of the revision component of the version number for this
instance.

Hope this help,


Nov 15 '05 #6

P: n/a
Does your AssemblyInfo.cs have a line that looks like this?

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

If so, the build number should increment correctly.

Chris

"Abe Frohnman" <us******@SPAMexperimentzero.org> wrote in message
news:DB*********************@news.easynews.com...
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

Ignacio Machin wrote:
Hi,

Try : Assembly.GetExecutingAssembly().GetName.Version , that return a
Version instance, this class implement these properties:

Public Properties
Build
Supported by the .NET Compact Framework.
Gets the value of the build component of the version number for this instance.
Major
Supported by the .NET Compact Framework.
Gets the value of the major component of the version number for this instance.
Minor
Supported by the .NET Compact Framework.
Gets the value of the minor component of the version number for this instance.
Revision
Supported by the .NET Compact Framework.
Gets the value of the revision component of the version number for this instance.

Hope this help,

Nov 15 '05 #7

P: n/a
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 Capel wrote:
Does your AssemblyInfo.cs have a line that looks like this?

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

If so, the build number should increment correctly.

Chris

Nov 15 '05 #8

P: n/a
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" <us******@SPAMexperimentzero.org> wrote in message
news:bM*********************@news.easynews.com...
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 Capel wrote:
Does your AssemblyInfo.cs have a line that looks like this?

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

If so, the build number should increment correctly.

Chris


Nov 15 '05 #9

P: n/a
Ahh...is there a way to make the build number autoincrement?

Chris Capel wrote:
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

Nov 15 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.