blah blah blah is here! blah blah » Close

up1down
link

I have a WPF application that I need to assign a version to. Is there a standard method for this? I see version information on the publish tab of the project properties but I am not using the publish feature. Ideally my version would consist of Major, Minor and Build.

I also need to gain access to this version number programatically. What's the WPF equivalent to System.Windows.Forms.Application.ProductVersion? Application.ProductVersion does not exist.

last answered one year ago

1 answers

link

You can set the version directly in the assemblyinfo.cs file
which can be found under the Properties node for the project in Solution Explorer.

If you scroll to the bottom of this file, there are a couple of assembly level attributes which, by default, look like this:

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

I'd set them both to whatever you want the version to be.

There isn't a WPF-specific way to get the product version programatically but, if you're using System.Windows.Forms.dll to get the FolderBrowserDialog control (as per your other question today), then you might as well use it to get Application.Productversion as well. As far as I can tell it should work fine for any type of application.

Another way to get at it is to use reflection:
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version

eeboy
499

Excellent... I can indeed access it using System.Windows.Forms. One issue still remains. Reading the AssemblyInfo.cs file i get the impression that by substituting a * in for a field VS will automatically increment the value. I tried this and it does not work. ProductVersion actually returns a '*'. [assembly: AssemblyVersion("0.1.*")] [assembly: AssemblyFileVersion("0.1.*")]

eeboy
499

Turns out the FileVersion is not incremented automatically. This link provided the information I needed: http://stackoverflow.com/questions/1158252/assembly-file-version-not-changing

Feedback