Deploying with Visual Studio 2012 (and Visual Studio 2010)

2013-07-18

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.

Visual Studio profile name in publish settings

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:

Visual Studio publish profiles

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