I always use the FileUpdate task from MSBuildCommunityTasks found at http://msbuildtasks.tigris.org/
You can use regular expressions to find a pattern and then replace in the desired text. For example: to replace the version number in the assembly-info.cs:
<FileUpdate Files="@(VersioningAssemblyInfoFiles)"
Regex="AssemblyFileVersion\(".*"\)\]"
ReplacementText="AssemblyFileVersion("$(VersionMajor).$(VersionMinor).$(VersionBuild).$(VersionRevision)")]" />
source
share