20
June
2014

Shared Assemblyinfo: Don't Repeat Yourself

by
Amido
,
5
minute read.
Share this article

One of the core principals of software development is “Don’t Repeat Yourself”, that is never do something twice in two different places.

Despite this core principal one of the most common areas of repetition is in the AssemblyInfo.cs file found in every single C# project, this file contains largely boilerplate content and could easily be shared across the solution by means of a Shared AssemblyInfo.

Before we delve in to the technical solution to this problem let’s quickly visit the attributes contained within AssemblyInfo.cs:

  • AssemblyConfiguration – textual representation of the configuration of this assembly, conditional compilation directives can be used here to provide different values to this attribute dependent on the inclusion of Debug Symbols with the assembly.
  • AssemblyCompany – the name of the company who owns and/or developed the assembly.
  • AssemblyProduct – the overarching product that the assembly comprises part of.
  • AssemblyCopyright – the copyright as it applies to this assembly, we recommend that this is set to something along the lines of “©2014 Amido Limited, All Rights Reserved”.
  • AssemblyTrademark – any trademarks as they apply to the assembly.
  • AssemblyCulture – the ISO 639 that this assembly represents, generally you are going to want to leave this as an empty string
  • ComVisible – setting this to false makes the types in this assembly invisible to COM components, if you need to access a type in this assembly from COM, set this to attribute to true on that type.
  • AssemblyVersion and AssemblyFileVersion – the four part, major.minor.revision.build, version number. We highly recommend using Semantic Versioning to provide structure to your scheme. You can use the AssemblyInformationalVersion to provide the full rich semantic version.
  • AssemblyTitle – the title of the assembly.
  • AssemblyDescription – friendly description of the assembly.
  • Guid – GUID that uniquely identifies the assembly to COM objects.

Of the above only AssemblyTitle, AssemblyDescription and Guid need to be tied specifically to the assembly all of the remaining attributes can be moved to a shared AssemblyInfo.

Assembly Properties

Creating the shared AssemblyInfo

The first step in avoiding repetition in your AssemblyInfo.cs is to create the shared file, simply duplicate one of your existing AssemblyInfo.cs file as SharedAssemblyInfo.cs into the root directory of your repository. It is best to surface this file in your solution by creating a solution folder called “Solution Items” in your solution and adding the SharedAssemblyInfo.cs to this folder, this will enable all of the Visual Studio Source Control functionality in addition to providing quick access to this key file.

If you have more than a handful of projects in your solution the next step has the potential to waste a considerable amount of time. There are two discrete tasks that you need to undertake to complete the conversion to a Shared AssemblyInfo:

  1. Link the file in each project file.
  2. Remove the common elements from from each AssemblyInfo.cs.

All of this can be automated, including the creation of a SharedAssemblyInfo.cs with this PowerShell script. I have also put a sample project up on GitHub to use as a playground to identify other use cases that are not covered by the script, feel free to fork, change and submit a pull request.

This script is idempotent and as such can be executed as many times over the solution as required, changes will only be made once and as such you can execute this script repeatedly as projects are added to the solution, bringing them into line as and when needed.

Amido needs the contact information you provide to us to contact you about our products and services. You may unsubscribe from these communications at any time. For information  please review our privacy policy.
Oops! Something went wrong while submitting the form.

Things you will learn

No items found.

Related content

No items found.

Need help plotting a route to the cloud?

We can help you define your digital strategy and turn it into a technical roadmap, achieving momentum to quickly deliver business value, whilst minimising risk.

Ask a question

If you consent to receiving communications from Amido, please subscribe using the checkbox below. If at any point you'd like to unsubscribe, you can do so using the links provided in our newsletters. You can review how your data is handled in our privacy policy.
Thank you, your submission has been received!
Oops! Something went wrong while submitting the form.