Reputation: 5121
I want to read and display WPF application publish version number in splash windows, In project properties in publish tab there is publish version, how can I get this and display it in WPF windows.
Thanks in advance
Upvotes: 35
Views: 44259
Reputation: 99
Use GetEntryAssembly
rather than GetExecutingAssembly
to get the version from the current executable rather than from the currently-executing DLL, like so:
string version = System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString();
Upvotes: 9
Reputation: 5351
string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
Console.WriteLine(version);
Upvotes: 5
Reputation: 514
Add reference to System.Deployment
library to your project and adjust this snippet to your code:
using System.Deployment.Application;
and
string version = null;
try
{
//// get deployment version
version = ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
}
catch (InvalidDeploymentException)
{
//// you cannot read publish version when app isn't installed
//// (e.g. during debug)
version = "not installed";
}
As stated in comment, you cannot obtain publish version during debug, so I suggest to handle InvalidDeploymentException
.
Upvotes: 31
Reputation: 222700
Access the assembly version using Assembly.GetExecutingAssembly()
and display in UI
Assembly.GetExecutingAssembly().GetName().Version.ToString();
Upvotes: 66