TeamCity variables are available as any environment variable is in MSBuild, as a property which can be accessed with the $() syntax.
This list defines the default TeamCity variables that are available to your build process. So teamcity.version is available as the environment variable TEAMCITY_VERSION and available to MSBuild as $(TEAMCITY_VERSION). (Environment variables are not case sensitive).
So to answer your question, a quick test to see if a build is running on the build server:
<Target Condition=" '$(TEAMCITY_VERSION)' != '' " >
<Message Text="Running on build server!..." />
</Target>
Or a real-world example which uses the TeamCity NUnit runner on the build machine and MSBuild Community Tasks if not:
<!-- Override the MSBuild Community Tasks NUnit task if building in TeamCity -->
<UsingTask Condition=" '$(teamcity_dotnet_nunitlauncher_msbuild_task)' != '' "
TaskName="NUnit" AssemblyFile="$(teamcity_dotnet_nunitlauncher_msbuild_task)" />