Long-time users of TFS may recall an era where using it required that their development machine have constant contact with the TFS server, even for relatively benign operations. This was because the TFS server would track the files you had on your development machine, which meant that all check-in and check-out operations required communication with the server.
The consequence of this behavior is that it makes offline work very difficult. In areas of poor network connectivity (on a plane, café, and the like), it may even mean work is prevented. Since the use of source control is something to be encouraged, this behavior is very frustrating, especially when conflicts emerge during check-ins and "get latest" operations.
In an effort to mitigate this, TFS sets the read-only flag on all files that are under source control, which only frustrates developers more, since they can't easily edit files unless they use a tool that is aware of this behavior and can properly communicate with TFS.
While there can be valid reasons to the historical approach, it would be best if the tools fit your workflow rather than adjusting your behavior to fit your tools. Local workspaces provide that exact flexibility. TFS is still the sole source of truth for source control, and is the only place where check-ins can occur. However, the decision over which files have been changed now occurs on your development machine, not on TFS.
Another benefit is that Visual Studio no longer needs to ask TFS if it can open a file for editing or not. Also, you can use any program you want to edit files, because the read-only flag is no longer applied to files. This change also improves the offline editing scenario, and you no longer need to mess around with the "go offline" and "go online" operations.
In this recipe, we'll make some changes to the source code so that you can see how this refined approach to source control works.
As before, you will need to have access to TFS in order to follow this recipe. It would be best if you also had a sandbox team project—a project where you can try things and change data without worrying about it affecting your normal work.
Start VS2015, connect to your team project, and you're ready to go.
Perform the following steps:
Class1.vb
, and open the file with Notepad or a favorite text editor that is not Visual Studio.Class1.vb
:Class1.vb
has been modified (it will have a checkmark next to it). Navigate to Team Explorer and within that, go to the Pending Changes tile. You should now see that Class1.vb
is listed as a pending change, as shown in the following screenshot:Class1.vb
. Edit the file in Notepad and change the class name to Class2
. Alter the comments in the body of the class to differentiate it further from the original before saving it and closing Notepad. Rename the copy as Class2.vb
.Class2.vb
, and click on Include in Project (marked by 2), as shown in the following screenshot:Class2.vb
file is now included as a pending change. Add a check-in Comment, and then click on Check In to reflect the changes, as shown in this screenshot:Class2.vb
to a name of your choice (our example will use SecondClass.vb
).Class2
, click on Yes. When this is done, just click on the Cancel button to close the Promote Candidate Changes window. The following is the screenshot of the Promote Candidate Changes window:When using a local workspace, Visual Studio creates a hidden local folder named $tf
, and stores within it zipped copies of the workspace version of your source files. Visual Studio detects changes by comparing the contents of your local files and folders to the contents of the $tf
folder, and adds any differences as pending changes.
It might be an obvious warning, but don't delete the $tf
folder or any of its contents, not even if you are short on disk space. Doing so will cause significant problems. If you want to examine this folder, a typical location would be C:UsersusernameSourceWorkspacesTFS_Repository_Name$tf
. Change username
and TFS_Repository_Name
to reflect your specific situation.
You might have noticed that at no time during the recipe did you have to change the read-only flag on any of the files, nor did you have to check-out any files for edit. In fact, the only time Visual Studio communicated with TFS was during the check-in process. All other changes were managed and tracked locally.
This should alleviate a lot of pain for people who have been used to older versions of TFS and the way server tracked workspaces operated.
The detected changes list can grow quite large over time, and you may want to ignore certain folders or files (for example, the /obj
and /bin
folders). You can either create .tfignore
files to specify the files and paths to ignore, or in Team Explorer, you can open the list of detected changes and exclude files either individually, by extension, or by folder path. Doing so will create or alter .tfignore
files for you, and add them to the Pending Changes list so that they can be checked in and shared with all the other developers on the team.
Be aware that when using a local workspace, you will no longer have any real visibility on the server over who has checked out a file. The exception to this is locking files. If you lock a file, the server is notified and can report that you have locked it.
Unshelving a shelveset now merges any shelveset changes with your local edits. Any conflicts between the shelveset and your local version will cause a merge conflict, and you will need to resolve it in the normal manner.
When might a local workspace not be appropriate? For many users, it is a good choice. But sometimes, you may have a large number of files in your TFS project (100,000+), or your personal workflow might be such that you use two or more open instances of VS2015 with the same project. In those situations, you will not want to use a local workspace.
By default, the partnership of VS2015 and TFS/VSTS will be set such that you are using a local workplace as described in this recipe. But if you would like to change your workplace setting for your project, or verify that it is in fact configured as you intend, you can take the following quick steps to view the settings.
18.218.168.16