Assembly Version

The AssemblyVersion attribute enables you to assign a version number to your assembly. Version numbers in .NET come in four parts:

• A major version number

• A minor version number

• A revision number

Each of these parts is separated by a period. The attribute takes a string parameter in its constructor that specifies the version number, as shown in the following example:

[assembly: AssemblyVersion("1.0.0.0")]

You must always specify a version number. If you specify a major and a minor version number, you can let the C# compiler autogenerate the other numbers when the code is built. You may want to do this if you want each build of your code to have a unique version number. By using the asterisk character for a build number, the C# compiler automatically assigns one. The generated build number is equal to the number of days since January 1, 2000, as shown in the following example:

[assembly: AssemblyVersion("1.0.0.*")]

This example gives the assembly a major version of 1, a minor version of 0, a revision number of 0, and a build number automatically assigned by the C# compiler.

If you use an asterisk for a revision number, the C# compiler automatically assigns a revision number and a build number. The generated revision number is equal to the number of seconds since midnight local time, modulo 2. The generated build number is equal to the number of days since January 1, 2000, as shown in the following example:

[assembly: AssemblyVersion("1.0.*")]

This example gives the assembly a major version of 1, a minor version of 0, and revision numbers and build numbers automatically assigned by the C# compiler.

The assembly product name is written to the assembly's manifest; it is also available in the Assembly Version, Product Version, and File Version fields of the compiled file's version information block.

Listing 21-2 adds assembly version attributes to the code in Listing 21-1.

Listing 21-2: Simple Windows Form Application with Version Information_

using System.Reflection; using System.Windows.Forms;

[assembly: AssemblyTitle("Listing 21-2")]

[assembly: AssemblyDescription("This executable was produced by compiling the code in Listing 21-2.")]

[assembly: AssemblyConfiguration("Retail")]

[assembly: AssemblyCompany("John Wiley, Inc.")]

[assembly: AssemblyProduct("C# Bible")]

[assembly: AssemblyCopyright("(c) 2002 John Wiley, Inc.")]

[assembly: AssemblyVersion("1.0.*")]

public class SimpleHelloWorld : Form {

public static void Main() {

Application.Run(new SimpleHelloWorld());

public SimpleHelloWorld() {

Text = "Hello, WindowsForms!";

0 0

Post a comment