Jump to content

Publish Version


crisoft
 Share

Recommended Posts

Depende da aplicação.

Se for uma aplicação web podes colocar uma key no ficheiro de config e ler esse key.


lblVersion.Text = ConfigurationManager.AppSettings["SITE_VERSION"];

Ou podes usar o reflection para ler a versão que colocaste na assembly do teu programa.


using System.Reflection;

	public static void AssemblyProperties(ref string product, ref string version)
	{
		try
		{
			Assembly objAssembly = Assembly.GetExecutingAssembly();


			foreach(Attribute attr in Attribute.GetCustomAttributes(objAssembly)) 
			{
				if (attr.GetType() == typeof(AssemblyProductAttribute))
				{
					product = ((AssemblyProductAttribute)attr).Product;
				}
				if (attr.GetType() == typeof(AssemblyVersionAttribute))
				{
					version = ((AssemblyVersionAttribute)attr).Version;
				}
			}

			string delimStr = ",=";
			char[] delimiter = delimStr.ToCharArray();
			string[] strAssembly = objAssembly.ToString().Split(delimiter);
			version = strAssembly[2];
		}
		catch(Exception ex)
		{
			Log(ex);
		}
	}

"There are two kinds of programmers. Those who write something to get the work done and those who want to write good code."João BrandãoWebsite e blog: http://jamab.blogspot.com/

Link to comment
Share on other sites

Muito obrigado.

Entretanto também descobri que que se inserir um novo item na minha aplicação desktop do tip About Box, posso adaptar a parit do código gerado toda a informação de que preciso:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;

namespace PPTime
{
    partial class AboutBox1 : Form
    {
        public AboutBox1()
        {
            InitializeComponent();
            this.Text = String.Format("About {0} {0}", AssemblyTitle);
            this.labelProductName.Text = AssemblyProduct;
            this.labelVersion.Text = String.Format("Version {0} {0}", AssemblyVersion);
            this.labelCopyright.Text = AssemblyCopyright;
            this.labelCompanyName.Text = AssemblyCompany;
            this.textBoxDescription.Text = AssemblyDescription;
        }

        #region Assembly Attribute Accessors

        public string AssemblyTitle
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
                if (attributes.Length > 0)
                {
                    AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];
                    if (titleAttribute.Title != "")
                    {
                        return titleAttribute.Title;
                    }
                }
                return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            }
        }

        public string AssemblyVersion
        {
            get
            {
                return Assembly.GetExecutingAssembly().GetName().Version.ToString();
            }
        }

        public string AssemblyDescription
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyDescriptionAttribute)attributes[0]).Description;
            }
        }

        public string AssemblyProduct
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyProductAttribute)attributes[0]).Product;
            }
        }

        public string AssemblyCopyright
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;
            }
        }

        public string AssemblyCompany
        {
            get
            {
                object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);
                if (attributes.Length == 0)
                {
                    return "";
                }
                return ((AssemblyCompanyAttribute)attributes[0]).Company;
            }
        }
        #endregion
    }
}


Mas não há dúvidas que o teu método resume exactamente o que eu precisava...

Muito obrigada, mais uma vez

crisoft

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.