Automatically adding version number to the code

Is there any method/technique/feature to add automatically incremented build number to the code (managed by software or tool)?
the build number can be used for viewing (hence traceability of the code).

More questions in this forum