Walkthrough: Creating and Building a C++ Project in Team Foundation Build

Visual Studio 2008

This topic presents the steps to create a C++ Win32 application, bind the project's source files to a Team Foundation server, and then build the project by using Team Foundation Build.


Required Permissions

To complete this walkthrough, 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.

To create and build a C++ Project in Team Foundation Build, perform the following procedures:

Creating the C++ application

Adding Source Code Files to the C++ application

Building a C++ Application by Using Team Foundation Build

Use the following steps to create the C++ project.

To create a C++ application

  1. Open Team Explorer and select the team project to which you want to add a C++ application.

  2. On the File menu of Visual Studio, point to New, and then click Project.

  3. In the New Project dialog box, under Projects types, expand the Visual C++ node, and click Win32.

  4. Under Templates, under Visual Studio installed templates, click Win32 Console Application.

  5. Type a name for the project. To complete the example described in this topic, type CardGame.

    When you create a new project, Visual Studio saves the project in a solution.

  6. Accept the default location and solution name for the solution.

  7. Select the Add To Source Control check box, and then click OK.

  8. In the Win32 Application Wizard, on the Overview page, click Next.

  9. On the Application Settings page under Application type, click Console Application. Under Additional options, select the Empty Project check box, and then click Finish.

    You now have a C++ project without source code files.

Use the following steps to create source files for a simple C++ project.

To add source code files to a C++ project

  1. Open Solution Explorer.

  2. Right-click the Header Files folder, point to Add, and then click Class.

  3. In the Add Class dialog box, in the Visual C++ category, click C++.

  4. In the Visual Studio installed templates area, click C++ Class.

  5. Click Add.

  6. In the Generic C++ Class Wizard, in Class name, type CardGame. Accept the default file names and settings and then click Finish.

  7. Replace the code in CardGame.h with the following code:

    #pragma once
    class CardGame
            int players;
            static int totalparticipants;
            CardGame(int p);
  8. Replace the code in CardGame.cpp with the following code:

    #include "CardGame.h"
    #include <iostream>
    using namespace std;
    CardGame::CardGame(int p)
        players = p;
        totalparticipants += p;
        cout << p << " players have started a new game.  There are now "
             << totalparticipants << " players in total." << endl;
  9. Add a source code file for the main program that tests the class.

    1. On the Project menu, click Add New Item.

    2. Under Categories, expand Visual C++, and then click Code.

    3. Under Templates, click C++ File (.cpp).

    4. In the Name box, type TestCardGames, and then click Add.

    5. In the TestCardGames.cpp editing window, copy and paste the following code:

      #include "CardGame.h"
      int CardGame::totalparticipants = 0;
      int main()
          CardGame *solitaire = 0;
          CardGame *goFish = 0;
                goFish = new CardGame(4);
          solitaire = new CardGame(1);
          delete solitaire;
          delete goFish;       
         return 0;
  10. On the Visual Studio Build menu, click Build Solution.

    1. The Output window opens and indicates that the project compiled without errors. If not, compare your code to the code that appears in this topic.

  11. Check in your changes to Team Foundation version control.

    1. On the Visual Studio View menu, click Other Windows.

    2. Click Pending Changes and then click Check In.

Use the following steps to build the C++ project.

To build a C++ project in Team Foundation Build

  1. On the View menu, click Team Explorer.

  2. In Team Explorer, select the team project that holds the source-controlled C++ solution files.

  3. On the Build menu, click New Build Definition.

  4. In the Build definition name box, type C++BuildDefinition.

  5. Click the Project File tab.

  6. Click Create.

  7. In the MSBuild Project File Creation Wizard, select the C++ solution that you checked into version control, CardGame.sln. Clear the selections for any other files, and then click Next.

  8. Click Next to accept the default configuration settings.

  9. With no Build options selected, click Finish.

  10. In the Build Definition dialog box, on the Build Defaults tab, select a Build agent.

  11. In the Builds will be staged to the following share box, type a build staging location, and then click OK to create the build definition.

  12. In Team Explorer, open the Builds folder of your team project, and then click the name of the build that you just created.

  13. On the Build menu, click Queue New Build.

  14. In the Queue Build dialog box, click Queue.

Community Additions