Setting Version Number in .NET 6.0/7.0 Applications

February 22, 2023

Back in the old days (?) of .NET 4.8, assembly version numbers were located in the AssemblyInfo.cs file.

...
[assembly: AssemblyVersion("5.1.0.0")]
[assembly: AssemblyFileVersion("5.1.0.0")]

Now in .NET 6.0 (and beyond), the Assembly.Info.cs file does not exist. Now you change the version by editing the project (*.cs) file.

Edit the Project File

Double click the project file and the contents are now immediately visible. (No more unloading the project before you can see its file contents. Nice!) If not there already, you need to add the version XML elements. Below are various flavors of version prefix and suffix settings.

<PropertyGroup>
  <VersionPrefix>5.1.0</VersionPrefix>
  <VersionSuffix></VersionSuffix>
</PropertyGroup>

You will notice that the file version will follow the VersionPrefix setting and pad out the right side, if necessary, with zeros. The product version will concatenate the VersionPrefix and VersionSuffix exactly as specified. Any project that does not have the XML elements will have all versions set to 1.0.0.0.


Now let’s add the suffix “Production”.

<PropertyGroup>
  <VersionPrefix>5.1.0</VersionPrefix>
  <VersionSuffix>Production</VersionSuffix>
</PropertyGroup>

Further

You can also set the version information with the dotnet pack command but that is left as an exercise for the reader.