Allen Zhang Allen Zhang - 1 month ago 16
C# Question

How to use release date as assembly version for a .net project?

I know that the format of the assembly version is:

<major version>.<minor version>.<build number>.<revision>


Is there a way to make the version number the current date?

For example, if I compile the build today, the version number should look like this:

2016.02.11.xxxxx


Where xxxxx is what you normally get if you set the assembly version to 1.0.0.*.

I googled around but didn't find an answer (not even a question) for this.

Answer

This can be done via MSBUILD. Here is a good description for it. You don't need a build server for this. You can call your custom MSBUILD target in the BeforeBuild Target of your project. For that open your csproj file with an editor and locate this section at the end of the file:

<!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->