How to auto publish a website each time a #TFS build succeeds?

Once you set up your TFS build server with an automated build, the big boss will ask you to publish the web project to the intermediate server each time a new build occurs. This might be for the testers to make sure that the code is working properly.


What to do? You analysed that, it will hamper your productivity. Isn’t it? Then what to do? Can we automate the build server to deploy the new code each time it succeeds? Let’s discuss it.


Automate Deploy after each Build

You might have already created the build definition in your TFS server for either manual or automated build (compilation of your source code) and to reduce your effort of deployment, now you want to automate the publishing of your web project to the server. This will not only reduce your burdens but also make sure that your server has the latest code always for testing.


To implement this, edit the build definition (you must be a TFS build Administrator) and navigate to the “Process” tab. There in the build process parameters section, find out the key named “MSBuild Arguments”. Enter the following configuration settings there in a single line separated by a single space:


/p:DeployIisAppPath="Default Web Site/MyBlog"  
/p:password=[email protected]


*** Make sure to change the text marked in blue with the proper values of your server.

    • /p:DeployOnBuild=True will ask the TFS build agent to deploy the build to the server when the process succeeds.
    • /p:DeployTarget=MsDeployPublish will notify the build server to execute the Microsoft deployment process.
    • /p:MSDeployPublishMethod=RemoteAgent will ask the build server to run the remote agent for the deployment.
    • /p:CreatePackageOnPublish=True will create a package of the current build for deployment.
    • /p:DeployIisAppPath=”Default Web Site/MyBlog” will deploy the package to the “MyBlog” web application. Change this value based on your webserver configuration. Make sure that the application is already created in the IIS.
    • /p:MsDeployServiceUrl=kunal-chowdhury.com is the Server URL where you want to deploy your application. Make sure to change the value with your server’s domain name.
    • /p:username=kunal-chowdhury.com\Webmaster is the administrative account of your server. Change this value with proper username. You should specify it in this format: “DOMAIN\USERNAME”.
    • /p:[email protected] is where you have to specify the password of the administrative user account (i.e. the username that you specified)

Once you set it up as shown below, the TFS build server will automatically trigger a web deployment each time the build succeeds. This could be a manual, CI (Continuous Integration) or an automated/scheduled build.


Here is a screenshot of the configuration settings, that you will modify as discussed above:


TFS Build Error - MS Build Arguments


That’s all about it. Trigger a manual build of this definition to check how it actually occurs. This will start compiling your solution, prepare a package of the binaries and resources once succeeds, then it will automatically deploy it to the server that you specified in the MSBuild Arguments.


Isn’t it so simple? I hope, this will now reduce your unnecessary work and improve your productivity. Just create the definition and forget about everything. Drop a line below if the post was helpful to you.


Connect with me on Twitter, Facebook and Google+ for the latest article updates and technical discussions. Don’t forget to subscribe to my blog’s RSS feed and Email Newsletter to get the article updates directly to your inbox. Happy Friday!!!

If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter, Facebook, Google+ and LinkedIn. I would love to hear your thoughts and opinions on my articles directly.

Also, don't forget to share your views and/or feedback in the comment section below.


  1. Great Article. One of the first examples using TFS 2012 that did not deploy to Azure.

    I have a web.config transform for each enviorment( dev server, qa server, prod server). When TFS does automatic deployment, how do I specify which Web.config File Transformations to use?

  2. Nice. Looks like I have to try many things today. By the way, will it work for all web application project?

  3. To use a Web.config Trasform, try this : http://blog.dontpaniclabs.com/post/2011/03/29/Transforming-AppConfig-Files-in-a-TFS-Build

  4. You can use
    to build and deploy using the 'Prod' configuration (i.e. web.config.prod)

  5. What about a solution with multiple projects that needs to be deployed to different apps on the IIS server?

  6. Yeah would also like to know the answer to the above.
    Got 28 projects, 8 web sites and 8 windows services.
    Need to deploy each and every one after the build is complete.

  7. Theres no effect with me. :(

  8. This post was very enlightening. Why is this feature so hard to learn about! All I could find for the longest time was references to OctopusDeploy and some really expensive MS product. If you can cater for multiple websites as a few other commenters have asked, then you could have web CI actually working! ASIDE: still I don't get why this is such a hard thing...?!

  9. Is there any way to build and publish using web deploy WITHOUT specifying a plain text password in the build configuration? Ideally, no password at all!

  10. Ste Porritt: In your build arguments specify /p:Authtype=NTLM /p:username="" and it will use the credentials of the user\service that is running the build on the build server.

  11. This is not worked for tfs 2013 build.

  12. /p:DeployOnBuild=true /p:PublishProfile="Release"

  13. After the build process does not give me the compiled files.
    I want to be like transactions such as Visual Studio app publisher

    I used below conf put MSBuild Arguments but I did not work



© 2008-2018 Kunal-Chowdhury.com | Designed by Kunal Chowdhury
Back to top