jcfmarkes

I`d like to now how to get the publish version that apears in the project properties.

I have tried the following code:

this.label2.Text = Application.ProductVersion.ToString();

but it appears to get a different version, it gets the version of the dlls (1.0.2753.27079) and i want the 1.0.0.4 version of project properties.

Can anyone help



Re: Visual C# General How to get the publish version [Major,Minor,Built,Revision]

OmegaMan

I give an example on my blog entitled Extracting the Assembly Version in .Net, but you need to extract the information using reflection from the current assembly.





Re: Visual C# General How to get the publish version [Major,Minor,Built,Revision]

Camalot

Try something like this.

Code Snippet


Version version = Application.ProductionVersion;
if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed) {
System.Deployment.Application.ApplicationDeployment ad = System.Deployment.Application.ApplicationDeploymen t.CurrentDeployment;
version = ad.CurrentVersion;
}





Re: Visual C# General How to get the publish version [Major,Minor,Built,Revision]

jcfmarkes

Sorry but Application does not have a ProductionVersion and second and most important

System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed is false.





Re: Visual C# General How to get the publish version [Major,Minor,Built,Revision]

jcfmarkes

OmegaMan how can i use reflection from the current assembly



Re: Visual C# General How to get the publish version [Major,Minor,Built,Revision]

MABderHelvetier

Hi

I'm not sure whether I understand you correctly, but this is what I would do:

Code Snippet

System.Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
System.Diagnostics.Debug.WriteLine(String.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Revision, version.Build));



Hope this helps ...




Re: Visual C# General How to get the publish version [Major,Minor,Built,Revision]

jcfmarkes

sorry but I already got that result version (1.0.2754.19709). What I want is the version stated in the last application manifest that was publish. You can see it by clicking with the right mouse button in the project and choosing its properties (see tab named "Publish"). In my case the last updadted version has the name:

GestorLicencas_1_0_0_3.application

I hope it was clear. Please give me feedback on this! Thanks!





Re: Visual C# General How to get the publish version [Major,Minor,Built,Revision]

Camalot

System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed will only be true if you are running it from the published location. if you are running from the visual studio or directly off the disk, then it will be false. you would have to publish, and then run the published application for it to be true.

also that was a typo on my part. i ment to type ProductVersion not ProductionVersion





Re: Visual C# General How to get the publish version [Major,Minor,Built,Revision]

jcfmarkes

Thank you it works, But i had to install the program again

i only use the following code

if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed){

System.Deployment.Application.ApplicationDeployment ad = System.Deployment.Application.ApplicationDeployment.CurrentDeployment;

this.label2.Text = ad.CurrentVersion.ToString();

}





Re: Visual C# General How to get the publish version [Major,Minor,Built,Revision]

OmegaMan

jcfmarkes wrote:
OmegaMan how can i use reflection from the current assembly


Reflection can be done on any assembly. Reflection is just a term to dynamically browse or instantiate objects at runtime. In my blog article that I mentioned, one is reflecting the assembly version information off of the current executing assembly.

Try my code in a console application, away from your app to get a feel for how it works.