use wpp files to xml peek your publish settings which will make a publish profile on the runtime of msbuild. use below xml snippet to create the wpp file.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
When using this file you must supply /p:PublishSettingsFile as a parameter and /p:DeployOnBuild=true
-->
<PropertyGroup Condition=" Exists('$(PublishSettingsFile)')">
<!-- These must be declared outside of a Target because they impact the Import Project flow -->
<WebPublishMethod>MSDeploy</WebPublishMethod>
<DeployTarget>WebPublish</DeployTarget>
<PipelineDependsOn>
GetPublishPropertiesFromPublishSettings;
$(PipelineDependsOn);
</PipelineDependsOn>
</PropertyGroup>
<Target Name="GetPublishPropertiesFromPublishSettings" BeforeTargets="Build" Condition=" Exists('$(PublishSettingsFile)')">
<PropertyGroup>
<_BaseQuery>/publishData/publishProfile[@publishMethod='MSDeploy'][1]/</_BaseQuery>
<!-- This value is not in the .publishSettings file and needs to be specified, it can be overridden with a cmd line parameter -->
<!-- If you are using the Remote Agent then specify this as RemoteAgent -->
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
</PropertyGroup>
<ItemGroup>
<_MSDeployXPath Include="WebPublishMethod">
<Query>$(_BaseQuery)@publishMethod</Query>
</_MSDeployXPath>
<_MSDeployXPath Include="MSDeployServiceURL">
<Query>$(_BaseQuery)@publishUrl</Query>
</_MSDeployXPath>
<_MSDeployXPath Include="SiteUrlToLaunchAfterPublish">
<Query>$(_BaseQuery)@destinationAppUrl</Query>
</_MSDeployXPath>
<_MSDeployXPath Include="DeployIisAppPath">
<Query>$(_BaseQuery)@msdeploySite</Query>
</_MSDeployXPath>
<_MSDeployXPath Include="UserName">
<Query>$(_BaseQuery)@userName</Query>
</_MSDeployXPath>
<_MSDeployXPath Include="Password">
<Query>$(_BaseQuery)@userPWD</Query>
</_MSDeployXPath>
</ItemGroup>
<XmlPeek XmlInputPath="$(PublishSettingsFile)"
Query="%(_MSDeployXPath.Query)"
Condition=" Exists('$(PublishSettingsFile)')">
<Output TaskParameter="Result" PropertyName="%(_MSDeployXPath.Identity)"/>
</XmlPeek>
</Target>
</Project>
create a wpp file with above xml code snippet and place it the same project where your csproj exists or if you are placing the wpp outside the csproj file folder to re-use in multiple projects then you need to add /p:WebPublishPipelineCustomizeTargetFile=
msbuild.exe MyProject /p:WebPublishPipelineCustomizeTargetFile=<path-to.targets-file> /p:VisualStudioVersion=11.0 /p:DeployOnBuild=true /p:PublishSettingsFile=<path-to-.publishsettings>
You can find more details on implementations @ http://sedodream.com/2013/06/05/HowToPublishAVSWebProjectWithAPublishSettingsFile.aspx