How to define release build string?

I would like to define a release build string, e.g. "Build 123", such that, this build string in compiled to all C# applications and displayed on their Windows title.

For example:

  • myApp Build 123,
  • myBrower Build 123.

What is the best way to implement this in C#

Regards, Charles



Answer this question

How to define release build string?

  • Mürşit Hakan ÇİL

    You can get the assembly (dll or exe) information using Assembly class. Place this code in the program's main form's constructor, it will get the assembly's name and build.

               System.Reflection.AssemblyName assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName();
                this.Text = assemblyName.Name;
                this.Text += " Build " + assemblyName.Version.Build;

    Be sure that in AssemblyInfo.cs -file (generated by visual studio), there's line as following:

    ...
    [assembly: AssemblyVersion("1.0.*")]  //Note the star, it makes visual studio to autogenerate build and revision numbers
    [assembly: AssemblyFileVersion("1.0.0.0")]
    ...

    You can manually set the build by replacing the star with your build and revision numbers.

  • Jared Brogni

    Create a class derived from System.Windows.Forms.Form, override the Text property (the set method) to add your build string, then use the derived form as the base of all you application. you can put your build string in a resource file so that you can alter it later without having to recompile or you can put it in an XML file. The simplest version of this is:

    public class BuildForm : System.Windows.Forms.Form{

    public override string Text{

    get{return base.Text;}
    //Here, you can first get the build string by implementing a static method GetBuildString() which will extract
    // the build string from a resource/XML file and return it. You then use the commented Line instead
    //set{base.Text = value + BuildForm.GetBuildString(); }
    set{base.Text = value + "Build 123";}

    }
    //If tou choose to store the value in a resource/XML file, you can create a static method to retreive the string
    //Remember in such case to use the commented line in the property override instead of the uncommented one
    //private static string GetBuildString(){..............}

    }

    Now, whenever you create an application, you can either choose Create/Add -> inherited form or you can manually make your form derive from BuildForm.

    That's the best i can think of right now!

    Hope it helped!



  • How to define release build string?