How to get the publishing version of an application console

Asked

Viewed 897 times

4

I’m having a problem trying to get the publishing version of my application, I searched and found the following answer on SOEN how to show Publish version in a textbox?

I followed exactly the concept of the right answer but an exception is thrown when trying to get the version of the application.

Version CurrentVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion;    
String version = CurrentVersion.Major.ToString() + "." + CurrentVersion.Minor.ToString() + "." + CurrentVersion.Build.ToString() + "." + CurrentVersion.Revision.ToString();

inserir a descrição da imagem aqui

1 answer

4

In order to prevent this exception from being cast, you can manipulate the property IsNetworkDeployed boolean type, returns true if the application is an application Clickonce, false if not.

using System.Deployment.Application;

if (ApplicationDeployment.IsNetworkDeployed)
{
   Version CurrentVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion;
   String version = CurrentVersion.Major.ToString() + "." + CurrentVersion.Minor.ToString() + "." + CurrentVersion.Build.ToString() + "." + CurrentVersion.Revision.ToString();
   // Faz alguma coisa aqui
}
else
{
   Console.WriteLine("Erro ao obter a versão de publicação");
} 

The estate CurrentDeployment is valid only within an application where the ClickOnce is implanted, as explained in description. In the forum of MSDN I found a snippet that can do this independent job whether it’s a Clickonce app or not.

System.Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
Console.WriteLine(String.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Revision, version.Build));
Console.ReadLine();
  • the second example the version always comes 1.0.0.0 even if the version of Build is different :(

Browser other questions tagged

You are not signed in. Login or sign up in order to post.