Get Version Number

N

Nathan

I have a VB project with a setup project in the same solution. Each time I
rebuild the setup project, I change the Version number in the setup
project's properties. Is there any way for my VB project to retrieve this
number?
 
N

Nathan

Application.ProductVersion does not give me the value I enter for the
Version property of the setup project. I entered 1.0.14. It gives me
1.0.1882.11172.
 
J

Jay B. Harlow [MVP - Outlook]

Nathan,
I don't know of a way to retreive the setup project version number.

What I do is manually (explicitly) set the setup project version to the same
value as the AssemblyInformationalVersionAttribute in my AssemblyInfo.vb
file.


The "easiest" way in VB.NET to get the Version number of a VB.NET Windows
Application is to use Application.ProductVersion, Application is found in
the System.Windows.Forms namespace.

To get the "product" Version of individual Assemblies I use the following
code to get the product version of specific assemblies:

Private Function GetProductVersion(ByVal [assembly] As
System.Reflection.Assembly) As String
Dim attributes() As Object
attributes =
[assembly].GetCustomAttributes(GetType(System.Reflection.AssemblyInformationalVersionAttribute),
False)
If attributes.Length > 0 Then
Dim assemblyProductVersion As
System.Reflection.AssemblyInformationalVersionAttribute =
DirectCast(attributes(0),
System.Reflection.AssemblyInformationalVersionAttribute)
Return assemblyProductVersion.InformationalVersion
Else
Return String.Empty
End If
End Function


Similarly there is a Application.ProductName that will get the name of your
Product, Application.ProductName returns the value of the
AssemblyProductAttribute found in the AssemblyInfo.vb file of your project.
If you leave this attribute its default value of blank then you get the root
namespace of the project. However if you change the attribute's value then
you will get the new value.

I normally change the AssemblyProductAttribute to a displayable value & use
Application.ProductName as my message box titles.

Note Application.ProductVersion comes from the
AssemblyInformationalVersionAttribute if you add it to your AssemblyInfo.vb
file, if you do not add AssemblyInformationalVersion, then
Application.ProductVersion comes from the AssemblyVersionAttribute:

For example, if my root namespace is "TheGreatAndWonderfulApp", I might set
my AssemblyInfo.vb file as:

' somewhere in the AssemblyInfo.vb file:
....
<Assembly: AssemblyProduct("The Great & Wonderful Application")>
....
<Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyInformationalVersion("1.0.0")> ' Product Version

Hope this helps
Jay
 
N

Nathan

Thanks, Jay. That explains things a bit.

Jay B. Harlow said:
Nathan,
I don't know of a way to retreive the setup project version number.

What I do is manually (explicitly) set the setup project version to the
same value as the AssemblyInformationalVersionAttribute in my
AssemblyInfo.vb file.


The "easiest" way in VB.NET to get the Version number of a VB.NET Windows
Application is to use Application.ProductVersion, Application is found in
the System.Windows.Forms namespace.

To get the "product" Version of individual Assemblies I use the following
code to get the product version of specific assemblies:

Private Function GetProductVersion(ByVal [assembly] As
System.Reflection.Assembly) As String
Dim attributes() As Object
attributes =
[assembly].GetCustomAttributes(GetType(System.Reflection.AssemblyInformationalVersionAttribute),
False)
If attributes.Length > 0 Then
Dim assemblyProductVersion As
System.Reflection.AssemblyInformationalVersionAttribute =
DirectCast(attributes(0),
System.Reflection.AssemblyInformationalVersionAttribute)
Return assemblyProductVersion.InformationalVersion
Else
Return String.Empty
End If
End Function


Similarly there is a Application.ProductName that will get the name of
your
Product, Application.ProductName returns the value of the
AssemblyProductAttribute found in the AssemblyInfo.vb file of your
project.
If you leave this attribute its default value of blank then you get the
root
namespace of the project. However if you change the attribute's value then
you will get the new value.

I normally change the AssemblyProductAttribute to a displayable value &
use
Application.ProductName as my message box titles.

Note Application.ProductVersion comes from the
AssemblyInformationalVersionAttribute if you add it to your
AssemblyInfo.vb
file, if you do not add AssemblyInformationalVersion, then
Application.ProductVersion comes from the AssemblyVersionAttribute:

For example, if my root namespace is "TheGreatAndWonderfulApp", I might
set
my AssemblyInfo.vb file as:

' somewhere in the AssemblyInfo.vb file:
...
<Assembly: AssemblyProduct("The Great & Wonderful Application")>
...
<Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyInformationalVersion("1.0.0")> ' Product Version

Hope this helps
Jay


Nathan said:
Application.ProductVersion does not give me the value I enter for the
Version property of the setup project. I entered 1.0.14. It gives me
1.0.1882.11172.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top