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.
Prerequisites
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
On the File menu, point to New, and then click Project.
In the New Project dialog box, select Visual C# in the Project types pane. In the Templates pane, select Windows Application.
Type HelloWorldTest in the Name box. In the Location box, type C:\DeploymentProjects, or open the local workspace you selected for your team project.
Click OK.
HelloWorldTest appears in Solution Explorer, and the Form1.cs appears in the Windows Forms Designer.
On the View menu, click Toolbox to make the list of controls visible.
Drag a Button control to your form.
Double-click the new button to open the Code Editor. Visual C# has inserted a method called button1_Click.
Add the following code to the method:
private void button1_Click(object sender, EventArgs e) { MessageBox.Show("Hello World!"); }
On the File menu, click Save All to save your changes.
On the Build menu, click Build HelloWorldTest to build your solution and to verify there are no build errors.
To create a deployment project
Select the HelloWorldTest solution in the Solution Explorer, and on the File menu, point to Add, and then click New Project.
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.
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
Select the HelloWorldTestInstaller in Solution Explorer. In the File System Editor, right-click the Application Folder node, point to Add and then click File.
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.
On the File menu, click Save All to save your changes.
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.
Note
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
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.
Click Close to close the Configuration Manager dialog box and click OK to close the HelloWorldTestInstaller Property Pages dialog box.
On the File menu, click Save All to save your changes.
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.
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.
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
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.
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
On the View menu, point to Other Windows, and then click Source Control Explorer.
In Source Control Explorer, expand your team project in the Folders pane, and select TeamBuildTypes.
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.
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.
Double-click the TFSBuild.proj file to open it in the Visual Studio XML-editor.
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.
</ItemGroup> <Target Name="AfterCompile"> <Exec Command=""C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv""$(SolutionRoot)\HelloWorldTest\HelloWorldTestInstaller\HelloWorldTestInstaller.vdproj /Build "Debug|Any CPU""/> <Copy SourceFiles="$(SolutionRoot)\HelloWorldTest\HelloWorldTestInstaller\Debug\HelloWorldTestInstaller.msi" DestinationFolder="$(OutDir)" /> <Copy SourceFiles="$(SolutionRoot)\HelloWorldTest\HelloWorldTestInstaller\Debug\setup.exe" DestinationFolder="$(OutDir)" /> </Target> </Project>
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.On the File menu, click Save to save your changes, and then close TFSBuild.proj.
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
On the Build menu, click Build Team Project <team project name>.
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.
In the Team Build Browser, click the log file under the Summary heading. Examine the log file for any errors.
Note
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
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.
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.
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.
Navigate to <root>:\Program Files\Microsoft\HelloWorldTestInstaller.
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
Tasks
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