Walkthrough: Configuring Team Foundation Build to Build a Visual Studio Setup Project

You can customize Team Foundation Build by adding either custom tasks or by using MSBuild tasks that are executed at a specified point during the build process. This topic explains the steps that are required to customize a build type to use MSBuild Exec task to build a Visual Studio setup project.


You need the following to complete this walkthrough:

A client computer with

  • Visual Studio Team Edition for Developers installed

  • Team Explorer installed

  • An available connection to a Team Foundation Server.

  • Local directory to use as your workspace.

  • A Team Project that has

    • A Team Foundation Build type created.

    • A workspace for source control mapped to the local directory. For more information, see How to: Create a Workspace. This walkthrough uses the local workspace: C:\DeploymentProjects.

    • Source Control Enabled

      To make sure Visual Studio is configured to use Team Foundation source control, on the Tools menu, click Options, and then click Source Control. Select Visual Studio Team Foundation Server in the Current source control plug-in list box.

A build computer with

  • Team Foundation Build installed

  • Visual Studio must be installed on the build computer in order to use the MSBuild Exec task to call devenv.exe to build a setup project.

Required Permissions

To perform this procedure, you must have the Administer a build and Administer workspaces permission set to Allow. You must also have the Check in and Check out permissions set to Allow.

To create a team project, you must have the Create new projects permission set to Allow, and you must be a member of the SharePoint Central Admins group in Windows SharePoint Server and have Content Manager permissions in SQL Reporting Services.

You must have install permission on the computer on which you run the installer created by Team Foundation Build.

Creating a Visual Studio Project

The procedures in this walkthrough create a simple C# windows application that is used as an example for configuring Team Foundation Build to build a Visual Studio setup project.

To create a Visual Studio Windows application

  1. On the File menu, point to New, and then click Project.

  2. In the New Project dialog box, select Visual C# in the Project types pane. In the Templates pane, select Windows Application.

  3. Type HelloWorldTest in the Name box. In the Location box, type C:\DeploymentProjects, or open the local workspace you selected for your team project.

  4. Click OK.

    HelloWorldTest appears in Solution Explorer, and the Form1.cs appears in the Windows Forms Designer.

  5. On the View menu, click Toolbox to make the list of controls visible.

  6. Drag a Button control to your form.

  7. Double-click the new button to open the Code Editor. Visual C# has inserted a method called button1_Click.

  8. Add the following code to the method:

    private void button1_Click(object sender, EventArgs e)
                MessageBox.Show("Hello World!");
  9. On the File menu, click Save All to save your changes.

  10. On the Build menu, click Build HelloWorldTest to build your solution and to verify there are no build errors.

To create a deployment project

  1. Select the HelloWorldTest solution in the Solution Explorer, and on the File menu, point to Add, and then click New Project.

  2. In the Add New Project dialog box, in the Project Types pane, open the Other Project Types node, click Setup and Deployment Projects, and then in the Templates pane, click Setup Project. In the Name box, type HelloWorldTestInstaller.

  3. Click OK to close the dialog box.

    The project is added to Solution Explorer, and the File System Editor opens.

To add the HelloWorldTest application to the installer

  1. Select the HelloWorldTestInstaller in Solution Explorer. In the File System Editor, right-click the Application Folder node, point to Add and then click File.

  2. In the Add Files dialog box, open the location of HelloWorldTest.exe, select it, and then click Open.

    The location in this walkthrough is C:\DeploymentProjects\HelloWorldTest\HelloWorldTest\obj\Debug\HelloWorldTest.exe. Your file path may be different depending on the location of your local workspace.

  3. On the File menu, click Save All to save your changes.

  4. On the Build menu, click Build HelloWorldTestInstaller to build a local copy of the installer and to verify there are no build errors.

    To verify that the Setup project built the installer, open the output file location. You should see HelloWorldTestInstaller.msi and setup.exe in the output file location.


    To find the output file, right-click HelloWorldTestInstaller project in Solution Explorer and then click Properties. In the HelloWorldTestInstaller Property Pages dialog box, the Output file name box contains the location of the installer files.

To modify the vdproj-file to work with Team Foundation Build

  1. Right-click HelloWorldTestInstaller project in Solution Explorer and then click Properties. In the HelloWorldTestInstaller Property Pages dialog box click the Configuration Manager. Make sure that the Build box is selected for both HelloWorldTest and HelloWorldTestInstaller.

  2. Click Close to close the Configuration Manager dialog box and click OK to close the HelloWorldTestInstaller Property Pages dialog box.

  3. On the File menu, click Save All to save your changes.

  4. Locate the HelloWorldTestInstaller.vdproj file.

    The location in this walkthrough it is C:\DeploymentProjects\HelloWorldTest\HelloWorldTestInstaller. Your file path may be different depending on the location of your local workspace.

  5. Right-click HelloWorldTestInstaller.vdproj, point to Open With and then click Choose Program. In the Open With dialog box, select Notepad from the Programs pane, and then click OK to open HelloWorldTestInstaller in Notepad.

  6. Verify that all the file paths are listed as relative to the location of the HelloWorldTestInstaller.vdproj files. There should be no absolute paths listed.

To add and check-in HelloWorldTest to Team Foundation source control

  1. Right-click the HelloWorldTest solution in Solution Explorer and then click Add Solution to Source Control. A yellow plus-sign appears next to all the files and indicates that they are pending addition to source control. For more information, see How to: Identify Source Control Item Status in Solution Explorer.

  2. Right-click the HelloWorldTest solution in Solution Explorer and then click Check In. In the Check In - Source Files - Workspace: <Workspace name> dialog box, scroll to the files that are selected. Clear the Name box for HelloWorldTest.exe and then click Check In. The files are now checked in to Team Foundation source control.

    You do not have to check in the executable, because Team Foundation Build builds a new executable.

Modifying the Team Foundation Build Type

Before you build the HelloWorldTestInstaller project by using Team Foundation Build, you must either create a new build type, or use an existing build type that you can modify. For more information, see How to: Create a New Build Type. You must modify the build type project file to instruct it to build the setup project.

To modify the TFSBuild.proj file to build the setup project

  1. On the View menu, point to Other Windows, and then click Source Control Explorer.

  2. In Source Control Explorer, expand your team project in the Folders pane, and select TeamBuildTypes.

  3. On the viewing pane, select the build type you want to use for building HelloWorldTest and HelloWorldTestInstaller. If your Team Foundation Build Type is new, right-click the Team Build Type folder, and then click Get Latest Version. This action makes the files available to be checked out for editing.

  4. On the viewing pane, double-click your build type, right-click TFSBuild.proj, and then click Check Out for Edit. On the Check Out dialog box, select None- Allow shared checkout, and then click Check Out.

    A red check-mark appears next to the TFSBuild.proj file and indicates its source control status.

  5. Double-click the TFSBuild.proj file to open it in the Visual Studio XML-editor.

  6. Add the following code, in bold-type, to the end of the TFSBuild.proj file. Replace the drive letter C with a different drive letter if your drive is not C.

    <Target Name="AfterCompile">
        <Exec Command="&quot;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv&quot;&quot;$(SolutionRoot)\HelloWorldTest\HelloWorldTestInstaller\HelloWorldTestInstaller.vdproj /Build &quot;Debug|Any CPU&quot;"/>
        <Copy SourceFiles="$(SolutionRoot)\HelloWorldTest\HelloWorldTestInstaller\Debug\HelloWorldTestInstaller.msi" DestinationFolder="$(OutDir)" />
    <Copy SourceFiles="$(SolutionRoot)\HelloWorldTest\HelloWorldTestInstaller\Debug\setup.exe"
    DestinationFolder="$(OutDir)" />

    This uses the MSBuild exec task to build the HelloWorldTestInstaller setup project by invoking the devenv.exe program. The Release|Any CPU is used to specify the build configuration. For more information, see Exec Task. The MSBuild copy task is used to copy the .msi file to the release folder. For more information, see Copy Task.

    The AfterCompile target name specifies that the devenv.exe must build the .vdproj file after the compilation process has completed. For more information about the target names, see Understanding Team Foundation Build Configuration Files.

  7. On the File menu, click Save to save your changes, and then close TFSBuild.proj.

  8. In Source Control Explorer, right-click TFSBuild.proj, and then click Check In Pending Changes. You can optionally add a comment in the Check In - Source Files - Workspace: <workspace name> dialog box. Click Check In to check TFSBuild.proj into source control.

Running the Team Foundation Build Type

After you have modified the TFSBuild.proj file and saved the changes in Team Foundation source control, run the build type to build your deployment project.

To run the team build type

  1. On the Build menu, click Build Team Project <team project name>.

  2. On the Build "team project name" dialog box, select the build type you want to use, and then click Build.

    You can monitor the build process in Team Build Browser. For more information, see How to: Monitor Build Progress.

  3. In the Team Build Browser, click the log file under the Summary heading. Examine the log file for any errors.


    You can safely ignore the warning MSB4078: The project file "HelloWorldTestInstaller\HelloWorldTestInstaller.vdproj" is not supported by MSBuild and cannot be built. The file is built by the devenv.exe program that uses the MSBuild Exec task.

To install the generated setup file

  1. Locate the build drop location \\<drop location>\Public_build\HelloWorldTestBuild_<build number>\Release.

    The drop location is the same file share as the log file location and is listed under the Summary heading in the Team Build Browser.

  2. Copy the HelloWorldTestInstaller.msi and setup.exe files to a computer where you are a member of the Windows Administrator security group or have the Install permission set to Allow.

  3. Double-click the setup.exei file and follow the instructions on the installation wizard.

    The HelloWorldTestInstaller.exe is installed under the path <root>:\Program Files\Microsoft\HelloWorldTestInstaller.

  4. Navigate to <root>:\Program Files\Microsoft\HelloWorldTestInstaller.

  5. Double-click the .exe file to run the application.

Next Steps

You can modify the Visual Studio Setup project to configure the installation wizard for additional steps. For more information, see Windows Installer Deployment Concepts.

See Also


Walkthrough: Customizing Team Foundation Build with a Custom Task

Other Resources

Working with Build Types in Team Foundation Build
Managing Builds with Team Foundation Build