Monday, January 19, 2015

.NET Assembly Versioning

When adding a new project to a solution, an assembly file is created that contains attributes used to define the version of the assembly during compilation.

Assembly versions consist of four different parts ({Major Version}.{Minor Version}.{Build Number}.{Revision}):

  • Major Version
    • Manually incremented for major releases, such as adding many new features to the solution.
  • Minor version
    • Manually incremented for minor releases, such as introducing small changes to existing features.
  • Build Number
    • Typically incremented automatically as part of every build performed on the Build Server. This allows each build to be tracked and tested.
  • Revision
    • Incremented for QFEs (a.k.a. “hotfixes” or patches) to builds released into the Production environment (PROD). This is set to zero for the initial release of any major/minor version of the solution

An easy way to associate the project's assembly files is what I refer to as "shared assembly info". Referring to the assembly attributes that should be the same across all projects in the solution, such as AssemblyCompanyAttribute.

To implement this, create a file in the solution folder named SharedAssemblyInfo and then add a link in each project to SharedAssemblyInfo. You can also move the linked SharedAssemblyInfo into the Properties folder so that it sits side-by-side with the AssemblyInfo that is specific to each project in the solution.

I recommend placing the following assembly attributes in SharedAssemblyInfo (and, of course, removing them as necessary from the project-specific AssemblyInfo files):

  • AssemblyCompany
  • AssemblyCopyright
  • AssemblyTrademark
  • ComVisible
  • NeutralResourcesLanguageAttribute
  • AssemblyVersion
  • AssemblyFileVersion

The AssemblyInfo files typically have the following assembly attributes:

  • AssemblyTitle
  • AssemblyDescription
  • AssemblyProduct
  • Guid

Within the common library for a product, I would also recommend creating a version control object. This would be able to use the assembly file for displaying the application version number on a web application or logging.The class object would look something like:

Public Class VersionControl
  Public Shared Function RetrieveAppVersion() As String
    With Reflection.Assembly.GetExecutingAssembly().GetName().Version
      Return String.Format("{0}.{1}.{2}", .Major, .MajorRevision, .Minor)
    End With
  End Function
  Public Shared Function RetrieveDBVersion() As String
    Return "Database: " & DatabaseFunctions.SingleInt("SELECT DatabaseVersion FROM tblSystem", ConnectionInformation.GetSQLConnectionString())
  End Function
  Public Shared Function RetrieveDLLVersion() As String
    Return Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString
  End Function
End Class

No comments:

Post a Comment