The key to this publish dilemma is Publish Profiles, Using these will change your life forever.
Step 1. Creating a Publish Profile
These can be created manually but the easiest way is to use the publish wizard in Visual Studio 2012.
Right click on the project you want published and select publish.
You will need to actually publish the project in order for the Publish Profile to be created (that sucks!). Once you've published whether it worked or not there should be a publish profile saved in the properties folder underneath the published project:
Check that in to your source control so that is can be available on the build server.
Step 2. Automating the deployment
Ok, so now you have to prepare the command line arguments to run against msbuild. The following should be sufficient:
msbuild.exe
/p:publishUrl=LOCATION_OF_WHERE_YOU_WANT_YOUR_STUFF_DEPLOYED
/p:DeployOnBuild=true /p:PublishProfile=NAME_OF_PUBLISH_PROFILE.pubxml
/p:Configuration=Release
//the configuration property can be a custom configuration in order to apply web.config transformations
The publish profile can be created manually if you are using Visual Studio 2010; as long as the publish profile file is saved in the correct location all should be good. I have tested this against web applications that publish vis FTP and it works fine!.
References
- http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx
- http://www.hanselman.com/blog/TinyHappyFeatures3PublishingImprovementsChainedConfig...
- hhttp://sedodream.com/2012/10/27/MSBuildHowToSetTheConfigurationProperty.aspx
- http://sedodream.com/2012/08/19/VisualStudioProjectCompatabilityAndVisualStudioVersion.aspx
- http://stackoverflow.com/questions/13920146/using-msbuild-exe-to-publish-a-asp-net-mvc-4-project-with-the-cmd-line
- http://msdn.microsoft.com/en-us/library/dd465326(VS.100).aspx
- http://www.hanselman.com/blog/SlowCheetahWebconfigTransformationSyntaxNowGeneralizedForAny...
- http://stackoverflow.com/questions/8366091/how-do-i-use-web-config-transform-on-my-connection-strings