Version Number

  • Thread starter Thread starter Keith Smith
  • Start date Start date
K

Keith Smith

Is there a way to detect the version number (from the Setup portion) of my
project?

I would like to do something like this...

label1.Text=VersionNumber;
 
Notice that assemblies have 2 versions:

- AssemblyVersionAttribute: the version of the assembly. This attribute
always appears in the assemblyinfo.cs file.
- AssemblyFileVersionAttribute: the Win32 version of the file (if omitted,
it is set to the assembly version)

To get the first. you must get the executing assembly with
System.Reflection.Assembly.GetExecutingAssembly() and then the GetName()
method returns an AssemblyName object which has a Version property.

To get the second, once you have the executing assembly you can retrieve its
attributes until you find the AssemblyFileVersionAttribute attribute.

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com
 
Carlos,
In addition to AssemblyVersionAttribute & AssemblyFileVersionAttribute,
there is AssemblyInformationalVersionAttribute, aka Product Version.

If your AssemblyInfo.cs (AssemblyInfo.vb) file includes
AssemblyInformationalVersionAttribute, then
System.Windows.Forms.Application.ProductVersion will return the
Informational version otherwise it returns the AssemblyVersionAttribute.
AssemblyInformationalVersionAttribute is also used for the Product version
under Windows Explorer properties.

Normally I assign the same AssemblyInformationalVersionAttribute value to
each of my projects within a solution, which I also use in the Setup
Project.

Hope this helps
Jay
 
Carlos J. Quintero said:

I tried using this code, but that didn't get me the same version as my
Setup1 project (which is version 1.0.1). What am I doing wrong?

MessageBox.Show(System.Windows.Forms.Application.ProductVersion.ToString());
 
Keith,
MessageBox.Show(System.Windows.Forms.Application.ProductVersion.ToString());

You need to explicitly (manually) set AssemblyInformationalVersionAttribute
to the exact same value as the Setup Project.

I normally put AssemblyInformationalVersionAttribute in the AssemblyInfo.cs
file.

I normally set both when I am ready to release a build of the solution.

Hope this helps
Jay
 
Back
Top