Ensure Your Assemblies are Versioned

Share This Article:

You can see the version number of a .NET assembly by right clicking and selecting properties. Under the Details tab you can see the File Version and Product Version. See the image below.

file_details

There is a 3rd version number, assembly version, that is not shown in the dialog above. Using Telerik’s free tool JustDecompile I can see the assembly version number as illustrated below.

assembly_version

Stuck at Version 1.0.0.0?

If you see File version 1.0.0.0, Product version 1.0.0, and Assembly version of 1.0.0.0 then the default assembly versioning is being used. This is a HUGE problem for code traceability. You won’t be able to efficiently determine where the code came from if you don’t stamp your assemblies. You should be able to trace back to the build, release, and code commit from the file version. When all your assemblies are 1.0.0.0 then it makes verifying code was deployed correctly more difficult and error prone.

The version numbers are stamped to an assembly during the compile process. In .NET the assembly information is controlled via one of 3 ways:

  1. Attributes in an AssemblyInfo.cs file (older .NET projects use this by default)
  2. Properties in the csproj file (newer .NET Core projects use this by default)
  3. Passed in via property flags to the msbuild command and can be combined with 1 or 2

We recommend setting AssemblyVersion, FileVersion, and InformationalVersion by default.

.NET Core Assembly Versioning

If you are using .NET Core then you would set them when compiling your solution file via dotnet build, e.g.

dotnet build .\ConsoleApp1.sln /property:Version=1.0.1

If you prefer to use the existing AssemblyInfo.cs file approach then you can still do this with .NET Core if you do the following:

Add the following code snippet to your csproj file

<PropertyGroup>
   <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

Add the AssemblyInfo.cs file to your project and set assembly info in that file. PROTIP: If you have more than one project then you can use one AssemblyInfo.cs file across all of your projects by adding the shared AssemblyInfo.cs file to each project as a link. When using a shared AssemblyInfo.cs file we recommend renaming the file to CommonAssemblyInfo.cs or SharedAssemblyInfo.cs for clarity.

Summary

Stamping your assemblies is an essential part of any build process. Adding the version information will allow you trace the origin of the code. Version information is important when troubleshooting issues and provides a mechanism to verify the deployed code is the correct version.

References

  • https://www.telerik.com/products/decompiler.aspx
  • https://andrewlock.net/version-vs-versionsuffix-vs-packageversion-what-do-they-all-mean

Related Articles

Need Help with an Upcoming Project