HowTo: AssemblyInfos – Keep it DRY!

 

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]

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

About the author

Written by Code Inside Team

Learn more about our team.

2 Responses

  1. Thanks for the useful article

    Reply
  2. Pretty cool! I’m using Albacore to generate the assemblies but this is a pretty good tip!

    Reply

Comment on this post

Recent Posts

  • Automated Security Analyser for ASP.NET websites

    Evil Hackers are lurking everywhere and many Web-applications are delicately and share “too much” with the attacker. A quick (first!) overview offers the Tool “ASafaWeb”. All the website does is making a few requests and writing an Analyses including problem solving’s. There are no permanent disadvantages (bad requests/ DoS attacks and so on). Example: KnowYourStack.com ...

  • image1489-570x194.png
    „Sign in with Twitter“ for your own ASP.NET WebApp

      “Sign in with Twitter” is a popular practice to authenticate the users on your website. One advantage compared to an own registration is the lower inhibition for the user. But on the other hand Twitter doesn’t fess up with all the information’s and you will get into a kind of addiction. At the end ...

  • image1485-570x194_thumb.png
    CodePlex is going to be updated

      CodePlex the Microsoft Open Source Project Hosting Plattform hasn’t changed that much in the last few years and for a few times I thought Microsoft stopped the whole developing process. But now I found out that there is still life in the project. Maybe it is because of the success of GitHub or because ...

  • image1474_thumb.png
    What does Adobe in the flash-free web? Magazine-Style Layouts with CSS Regions!

      Adobe is well known for Photoshop and Flash but of course there is a lot more. According to the “Future Post” from Google Adobe declared one of their big subjects on a Blogpost. I’m talking about the W3C Working Draft to CSS Regions. Adobe cooperates with the WebKit Team and W3C on this. What ...

  • image1471-523x194.png
    HTML 5 Games, Tooling & 3D

      Game Developing is an interesting subject for all kind of software developer. But as a web developer without any Flash-skills there aren’t that much starting points. With HTML5 and the combination between Javascript, CSS3 and fast browsers there are the first “robust” HTML5 games. HTML5 games? Is this real? Neowin created a “Top 10” ...

Support us