Every once in awhile I hit a (technical) wall, stumble upon a great tool or look for a reason to improve my English.
This is my place to share, welcome to my logs.
There are many ways to handle multiple (web) projects in a solution and deploy them on build. I've seen many examples and all examples required loads of configuration. I believe this is the easiest way, for this to work you need Team Foundation Server as your Version Control software.
The Solution contains a total three projects. Example:
.- DemoSolution | |-- Webshop (Web Project, MVC) | |-- DAL (Class Library) | |-- API (Web Project, MVC)
On build we want to deploy (web publish) the Webshop and the Api to our development server. Even better, we setup Continues Integration for this solution and deploy our web projects to the development server on TFS checkin.
At the moment I was using a Build Definition that contained all the MSBuild Arguments to publish to a single IIS Website. As explained in this article (thanks Kunal, for writing this excellent article), but we can't publish every Web Project to the same IIS website. This will result in the last Web Project being published, overwriting our Webshop with in our case the API.
Visual Studio 2012 introduced
Publish Profiles this is the first step in solving our problem. But before we can create a Publish Profile we need to make sure that our server is configurated to support Web Deployments, here is great guide to achieve just that!
Solution Explorer file tree select the first Web Project that you want to Deploy on Build, in my case
Webshop. Now rightclick and click on
Publish.... A wizard is presented, follow these steps:
< New Custom Profile >.
Developmentas the name of the Publish Profile (this is an important step) and click OK.
Web Deployas the Publish Method.
Do this for all Web Projects that you want to Deploy on build, make sure you enter
Development for each profile name..
Click on the
Team Explorer tab in the Solution Explorer pane or through View → Team Explorer in the Visual Studio ribbon. Now select the option
Builds (can't find Build, use the home icon at the top of the Team Explorer pane). Then click the blue link
Create New Build Definition. Give the Build Definition a logical name, something like 'Continues Integration' and follow these steps:
Triggersection and check
Continues Integration - Build each check-in.
Source Settingssection and setup the paths as desired.
Build Defaultsection and setup the options as desired, I used my default Build Controller and checked
This build does not copy output files to a drop folder.
Processsection, this is the important part.
Process section open, expand section 2. Build and then expand section 5. Advanced. Enter the following in as the
MSBuild Arguments (as one long line, arguments devided by spaces):
/p:DeployOnBuild=True /p:PublishProfile=Development /p:AllowUntrustedCertificate=True /p:Password=password-of-your-deploy-user-as-earlier-entered-with-publish-profile
Now save the Build Definition (CTRL + S or File → Save).
Explanation of the arguments: /p:DeployOnBuild: Tells MSBuild that the (Web)Project needs to be deployed on Build. /p:PublishProfile: Tells MSBuild the name of the Publish Profile to look for in each (Web)Project. /p:AllowUntrustedCertificate: Tells MSBuild that whenever the destionation server does not have a valid certificate to continue deployment. (Can be set to False) /p:Password: Tells MSBuild the password to associate with the Publish Profile. I know you entered this allready in the Publish Profile, but Visual Studio will encrypt, MSBuild can't use this, more information here.
This should cover it, when you make a change to your project and do a checkin the Continues Integration Build should kick in and start building. After that the build will be deployed / published by the rules setup in the Publish Profile.
If, for some reason you encounter errors you can manually try to use the Publish Profile. Rightclick on a Web Project and choose
Publish..., in the dialong click on Publish again. This should give you some extra pointers.
Still no luck? Check the build logs or comment on this article below.
The Profile Name binds everything together, you could add another Publish Profile to each project with the name Staging and Another with Production. You can now setup more Build Definition to leverage these profiles. I leave that to you.
If you still run into some troubles or have some questions feel free to comment or e-mail me.