01 December 2010 assembly info, DLL, Don't repeat yourself CI Team

image

Click right on a DLL and take a look on the detail-list of the characteristics and you will find all the different entries about the version and other stuff. For those thinks we are used to create an assembly info file during every project. But while you are doing so don't forget about the DRY principle: "Don't repeat yourself"

typical project structure

We have several projects in one solution and they are linked with each other in some way. In every Project we will find an Assemblyinfo file:

image

What's written in such an Assemblyinfo file?

Something like this:

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AssemblyInfoKeepItDry.Service")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("AssemblyInfoKeepItDry.Service")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2010")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ee7c20b8-30dc-4143-bf9c-59f2d53acd85")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Redundancy... everywhere!!

In every Assemblyinfo we find redundancy files like for example

- company

- product

- copyright

Depending if you are a product- or a project-firm you have different needs. I only work with projects and except the title, description and guid it's the same thing anyway because I deliver everything at once and don't want to make magic stuff with the DLL.

So what can I do? Solution!

1. Create a "GlobalAssemblyInfo" file: click right on the solution and create a new item.

2. Write "global" things into the solution (depending on the need):

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyCompany("Code Inside")]
[assembly: AssemblyProduct("Demoblogpost")]
[assembly: AssemblyCopyright("Copyright © Code-Inside")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

3. Remove "global" tings from the original Assemblyinfo. For example: this is how my Assemblyinfo from the service DLL looks like:

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: AssemblyTitle("AssemblyInfoKeepItDry.Service")]
[assembly: AssemblyDescription("")]
[assembly: Guid("ee7c20b8-30dc-4143-bf9c-59f2d53acd85")]

4. link the "GlobalAssembly" with "Add Existing Item" and navigate to the file. Press "Add a Link"!!! (otherwise a copy will be created and that´s not what we want)

image

image

Thats it!

Now we have just one location for our file. This could be very useful if you want to, for example, administrate the version-number. You are able to change the number at one location and every DLL will be created with the same. Easy but effective.

[Download Democode]