Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to show publish version in a textbox?

Tags:

c#

At the moment I am manually updating the version field (textbox) in my application every time I publish it. I am wondering if there is a way to have my application get that data from somewhere and display it in the box for me. I am using VS2012 and I am just unsure of how to achieve that in C#. Below is a screenshot of the VS2012 properties window that I am talking about.

Publish image from VS2012

NEW IMAGE:

enter image description here

like image 903
Shane Superfly MacNeill Avatar asked Jul 17 '13 03:07

Shane Superfly MacNeill


People also ask

How do I publish a major version of a document?

Hover over the title of the document with your mouse, click the drop-down arrow, and click Publish a major version. The Publish Major Version dialog box opens. Enter a comment in the Comments field and then click OK. Note: Comments are optional and make it easier to find a previous version.

How do I publish a major version of an ellipse?

Click the ellipses ( ... ), click More, and then click Publish. Click the ellipses ( ... ), click the ellipses again ( ... ), click Advanced, and then click Publish a major version. Click the ellipses ( ... ), click the ellipses again ( ... ), and then click Publish a major version.

How do I Unpublish a version of a document?

Hover over the title of the document with your mouse, click the drop-down arrow, and click Unpublish this version. When you are prompted to confirm that you want to unpublish the version, click OK.

How do I find the last version of a project?

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:


2 Answers

Don't forget to check if the application is networkdeployed otherwise it won't work in debug mode.

if (ApplicationDeployment.IsNetworkDeployed) {     this.Text = string.Format("Your application name - v{0}",         ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString(4)); } 
like image 200
LockTar Avatar answered Oct 01 '22 20:10

LockTar


Try this:

using System.Deployment.Application;  public Version AssemblyVersion  {     get     {         return ApplicationDeployment.CurrentDeployment.CurrentVersion;     } } 

Then the caller to the getter property can de-reference the Major, Minor, Build and Revision properties, like this:

YourVersionTextBox.Text = AssemblyVersion.Major.ToString() + "."                         + AssemblyVersion.Minor.ToString() + "."                         + AssemblyVersion.Build.ToString() + "."                         + AssemblyVersion.Revision.ToString(); 
like image 45
Karl Anderson Avatar answered Oct 01 '22 22:10

Karl Anderson