Data Browser - Viewing Site  Sector 23 Code Bank Logged in as:  Guest  


Setting up TFS 2010
Setting up TFS 2010 to build and deploy .NET web projects... what a lot of work, but it can be done!

Goal: Deploy a .NET 2010 solution containing 1 web application, 2 web sites, and several code libraries to a development web server, using a build server with TFS installed (or use the development server as the build server).

Reason: This is desired, as it would replace: VSS2008 (source control), Draco.NET (continuous integration tool), NANT (build tool), and MSBuild (deployment tool) with the built-in tools under "Team Explorer" in Visual Studio.

1. Install TFS 2010 Server on your build server. I chose Basic Installation, installed the server and the build tools. I put it on the development server as we don't have a separate build server available, but during the setup you will see a message saying this is not recommended as it may impact performance/security.

Verify visual studio can connect to TFS by selecting your build server in Team Explorer of a local copy of visual studio.
Make sure all visual studios are up to date with latest service packs and Team Explorer add on.
See my post titled 'Microsoft Fail' if you get connection errors.

2. Install "Web Deployment 3.0 or 3.5" package on your development server you want to push builds to. Otherwise TFS won't talk to it.
I think this is only needed if you have Web Applications (not web sites), but I'm not positive.

2.1 Install Management Service on IIS if it isn't already installed. Under Server Manager, click Roles, scroll down to IIS, and ensure this is installed. If not, use 'Add Role Service' to add the Management Service.
This is required in step 4 (web applications only)

2.2 Install Management Service Delegation on IIS if it isn't already installed.
Under Add/Remove Programs, select installed 'Web Deployment 3.0/3.5", right click-"Change", and ensure all features under IIS Deployment Handler are installed.

2.3 Add yourself as a user for web deploys on the IIS site you would like to build to; this will report the http path to use for the server connection.
For more info, see

3. On TFS server, TFS Admin Console, start the build configuration services using all defaults.
Make sure Visual Studio is installed on your build server or you may have to jump through hoops to get code to compile.

4. (Web Applications Only): On IIS dev server, click server name, go to Management Service, enable remote connections, and start the service. Under IIS Manager Permissions, add a Windows user who TFS will use to publish your websites.
I would recommend that you verify that you can manually publish a web deploy package before trying to get TFS to do it!
Click "Publish..."
Publish Method: Web Deploy
Service URL: http://servername
Site/application: Default Web Site/MyApp (configure this manually and use correct name)
Mark as IIS app: Yes
Leave extra files: Your choice
Credentials: The windows user you entered above

5. Now, try to get TFS to publish.
Team Explorer/Builds -> New Build Definition...
General: enter a name
Trigger: Manual (for testing) or Check-in/Rolling/Gated (once you're ready to go live)
Workspace: use default
Build Defaults: Enter a drop folder
Process: All the defaults are fine here, except you need to set your MSBuild Arguments if you have a web application (not web site). I used:
/p:DeployOnBuild=True /p:DeployTarget=MsDeployPublish /p:CreatePackageOnPublish=False /p:MSDeployPublishMethod=WMSVC /p:MSDeployServiceUrl=SERVERNAME /p:DeployIisAppPath="Default Web Site/WEBAPPNAME" /p:UserName=DOMAIN\USER /p:Password=PASSWORD /p:AllowUntrustedCertificate=True

Since the web application name is coded in here under DeployIisAppPath, this only works if you have one web application.
Multiple web projects (sites) are okay.
If you have multiple web applications, do not include the parameter "DeployIisAppPath". Instead, skip this parameter.
For each web application, right click on the project and click 'Properties".
Enter this path (Default Web Site/AppName) into the appropriate box on the Package/Publish Web tab.
These will be used for each project.

You can leave the MSBuild parameters blank if you're just compiling web sites (no .csproj file). Note that your project must be in a solution or the build task will not have valid defaults when you create it.

Retention Policy: leave defaults

6. Make sure all your third-party dlls are available to TFS to build. Add a solution-level folder such as "Libs" and drop them in there. Then in each of your projects, point to the dlls in this folder.

7. Right click on the build and Queue Manual Build, then double click the build object to view the status.
If you are lucky, it will compile all code into the drop directory you configured. It will also copy your web application to IIS per your MSBuild parameters. But, your web sites will be sitting in a subfolder of the drop directory: _PublishedWebsites. So, on to step 8...

8. Create a build task to copy .NET Web Sites (not applications) from _PublishedWebsites folder to your IIS directory:
Open Team Explorer, Builds
Right click your build, open process file location
Select the .xaml file used by your build configuration (DefaultTemplate.xaml or else you can create a new one in the build properties window).
Get latest version (will prompt you to configure a working directory if you haven't) and Check Out
Double click .xaml template to edit it.
Collapse All so you can see what you are doing
Toolbox - drag a "CopyDirectory" task after 'run on agent' and before 'check in gated changes'
Edit the copy task
Set Source=BuildDetail.DropLocation + "\_PublishedWebsites" - make sure you put the second part in Quotes!
Set Destination="\\servername\webshare" - make sure you put the destination in Quotes!
SAVE AND CHECK IN CHANGEs to this xaml file.
[note: I assume you could edit the task to simply put the websites directly into the webshare and bypass the drop folder altogether; I didn't want to mess around any more, so I did this as a simpler workaround]

You can also add a few delete tasks if you want to delete the old content in your IIS folder rather than simply copying over new content (if you are concerned about having extra files staying around).
If you do this, add a create task afterwards to create the directory back, or the copy to directory task will fail. I had to use a local path to get the CreateDirectory task to work.

9. Run another manual build. This time it should work!

Created By: amos 7/12/2013 4:54:08 PM
Updated: 7/20/2015 2:48:17 PM