How to create a Professional Versioning in a .NET Solution

This post explains the steps in setting up a professional versioning in a .NET solution.

Project versioning
In solutions, many projects can exist. It is important to structure the project so that when creating a release, all assemblies are set to the release version. This should be set as part of the release build, not manually or with some external build process tool etc. To do this, a GlobalAssemblyInfo class is used. This is linked to all projects but the file only exists once. To set the version number, only this file needs to be set and not every AssemblyInfo class in every project…

How to setup

1: Create a GlobalAssemblyInfo class.

[assembly: System.Reflection.AssemblyCopyright("Copyright © 2013. All rights reserved.")]
[assembly: System.Reflection.AssemblyConfiguration("Release")]
[assembly: System.Reflection.AssemblyVersion("")]
[assembly: System.Reflection.AssemblyFileVersion("")]
[assembly: System.Reflection.AssemblyInformationalVersion("")]

internal sealed partial class ThisAssembly {
    internal const string AssemblyCopyright = "Copyright © 2013. All rights reserved.";  
    internal const string AssemblyConfiguration = "Release";   
    internal const string AssemblyVersion = "";   
    internal const string AssemblyFileVersion = "";    
    internal const string AssemblyInformationalVersion = "";
    private ThisAssembly() {

2: Remove all the duplicate information in each AssemblyInfo class in each project. This is what it looks like after.

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("ClassLibrary1")]
[assembly: AssemblyDescription("a class description")]

// 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("231d3658-25f4-425a-b9c4-610f93d10e3e")]

3. Add the existing GlobalAssemblyInfo class as a linked class to each project.


Once you build your solution, all assemblies are built using the version defined in the GlobalAssemblyInfo class.

Now it is easy to set this version in a release build using msbuild. For example the NuGet MSBuildCommunityTasks provides a complete working example for this.


One comment

  1. Really enjoyed reading your article, the information you delivered in this post was damn good. Keep sharing your post with efficient news.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: