Поделиться через


Develop and share code in TFVC with Visual Studio

TFS 2018

Visual Studio 2019 | Visual Studio 2022

Whether your software project is large, small, or brand new, it's best to use version control as early as possible. This article shows you how to get started with Team Foundation Version Control (TFVC), a centralized version control system.

  • If you want to work in a distributed version control system, you can instead use Git with Azure Repos.

  • If you have code you want to migrate into Azure DevOps Services, see Migration options.

Prerequisites

Connect to your project

  1. In Visual Studio, from the Home page of Team Explorer, select the Manage Connections icon.

  2. On the Connect page of Team Explorer, right-click the project that contains your repository, and select Connect.

    Screenshot that shows selecting Connect to connect a project.

    If the project you want isn't listed, select Manage Connections, select Connect to a Project, and then select the project you want. For more information, see Connect from Visual Studio or Team Explorer.

Note

Some TFVC menu options aren't displayed in Visual Studio until you connect to TFVC.

Configure your workspace

  1. On the Home page of Visual Studio Team Explorer, select Configure your workspace to map the project to a folder on your dev machine.

  2. Confirm your workspace path, and select Map & Get to map the workspace and get your code.

    Screenshot that shows mapping the workspace to get code.

    Now you can check in source, queue builds, and manage work.

    Screenshot shows a success message that verifies that Visual Studio is now connected to your project.

If you don't see the Configure your workspace link, you might already have a workspace on your computer. To see existing workspaces, open Source Control Explorer, or look under Solutions in Team Explorer. For more information, see Use Source Control Explorer to manage files in TFVC and Create and work with workspaces.

Screenshot that shows Team Explorer, where you can select Source Control Explorer or Manage Workspaces.

Note

TFVC doesn't support workspaces on network drives or UNC paths.

Add your code to version control

  1. To create a new code project to put under TFVC source control, select New under Solutions in the Home page of Team Explorer. Put the new solution in your mapped workspace folder, such as c:\Users\<YourName>\Source\Workspaces\YourTeamProject\.

    Screenshot that shows the Team Explorer Home page with New highlighted under Solutions.

    Or, if you already have an app in progress that you want to put under TFVC source control, move the solution into your workspace folder in Windows File Explorer.

    Screenshot shows moving your source code to your workspace folder.

  2. Open your solution in Visual Studio.

    Screenshot shows Team Explorer Home page, where you can open your solution in Visual Studio.

  3. Press Ctrl+Alt+L to open Solution Explorer, and in Solution Explorer, right-click the solution and select Add Solution to Source Control.

    Screenshot of adding your solution to source control.

  4. In the Add Solution to Source Control dialog box, review the details, and then select OK.

Check in the solution

  1. When you're ready to check in your code, right-click your solution in Solution Explorer and select Check In.

    Screenshot that shows a context menu with Check In selected.

  2. On the Pending Changes page of Team Explorer, add a check-in comment and then select Check in.

    Screenshot that shows a Pending Changes pane with a comment and a Check In button.

  3. From the Home page of Team Explorer, select Source Control Explorer.

    Screenshot that shows the Team Explorer Home page with Source Control Explorer selected.

    In Source Control Explorer, you can see the solution in TFVC.

    Screenshot that shows the solution in Source Control Explorer.

Your whole team can work on the code now. All changes are tracked in version control.

Check in changes

  1. When you edit code in Visual Studio that's under TFVC source control, the changed file is automatically checked out. For example, site.css is checked out after the font-size has been changed to 16px.

    Screenshot that shows Solutions Explorer with the file site.css checked out.

  2. To compare the modified file with the latest version in source control, right-click the file in Solution Explorer and select Compare.

    Screenshot that shows the Compare option in the Solution Explorer context menu.

    The Diff window opens, and you can see the difference between the two versions.

    Screenshot that shows the compare window, with two versions of the file side by side.

  3. In Solution Explorer, right-click the file and select Check In to check in the change.

    Screenshot that shows the Check In option in the Solution Explorer context menu.

    You can also check in from the code editor or from Team Explorer.

  4. If you're working on a task or fixing a bug that's tracked as a work item, you can associate that work item with your pending changes. TFVC resolves the bug, closes the task, or links the changeset to the work item.

    Screenshot shows Related Work Items in pending changes.

  5. Add a comment and check in.

    Screenshot that shows where you can add a comment and check in the files.

  6. In Source Control Explorer, right-click the file you changed and select View History to view its history.

    Screenshot that shows View History in the source file context menu.

    The History window lists all the changesets that include this file.

    Screenshot that shows the History window with changesets.

Next steps