How to get the publishing version of a console application

4

I'm having a problem trying to get the publish version of my application, I searched and found the following answer in 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();

    
asked by anonymous 28.05.2014 / 19:01

1 answer

4

To prevent this exception from being thrown, you can manipulate the IsNetworkDeployed " of type Boolean, 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 CurrentDeployment is valid only within an application where ClickOnce is deployed, as explained in description . On the

28.05.2014 / 19:47