Which Teamcity version are you using? Teamcity 9.1 has a new build feature File Content Replacer
which allows you to replace contents of a file using regex. However earlier versions of teamcity do not have this in built, so for them you'll have a write it on your own, May be a powershell script or MSBuild target.
Sample code for MSBuild
target SetRevisionNumber
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="MSBuild.Community.Tasks.dll" TaskName="MSBuild.Community.Tasks.FileUpdate" />
<Target Name="SetRevisionNumber" Condition="$(RevisionNumber) != ''">
<Message Text="Setting Revision Number to $(RevisionNumber) in $(AssemblyVersionFile)" Importance="High" />
<FileUpdate Files="$(AssemblyVersionFile)"
Regex="\[assembly: AssemblyVersion\(.(\d+)\.(\d+)\.(\d+)\.(\d+)"
ReplacementText="[assembly: AssemblyVersion("$1.$2.$3.$(RevisionNumber)" />
</Target>
</Project>