What can you do if a file in TFS is locked by someone else?

This is another question that one of the attendees asked me during my talk. After some investigations, I found a workaround. To reproduce such scenario, I used two instances of Visual Studio 2008, namely instance1 (logged on as TFSSETUP) and instance2 (logged on as Administrator). I have a team project called TicTacToe. In instance1, I locked a file called Cell.cs.


Figure 1: To lock Cell.cs: Screenshot 1 of 2


Figure 2: To lock Cell.cs: Screenshot 2 of 2


Figure 3: To launch another instance of Visual Studio as Administrator


Figure 4: Attempt to unlock Cell.cs from the second instance of Visual Studio (launched as Administrator): Screenshot 1 of 2


Figure 5: Attempt to unlock Cell.cs from the second instance of Visual Studio (launched as Administrator): Screenshot 2 of 2

As shown in Figure 5, we are not able to unlock Cell.cs. To unlock Cell.cs on instance2, I perform the following steps:

If you still have the username of the person, you can simply do something like this:

1. Open up Visual Studio command prompt (Start -> Programs -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Command Prompt)
2. Run the following command:
tf lock /lock:none /workspace:WorkspaceName;USERNAME /recursive $/


Figure 6: To unlock Cell.cs using TF command (Note: You can ignore the error messages. As of now, we have successfully unlock Cell.cs. The error messages state files that we could not unlock.)

Now I attempt to check-in from the second instance of Visual Studio.


Figure 7: To check-in from the second instance of Visual Studio: Screenshot 1 of 2


Figure 8: To check-in from the second instance of Visual Studio: Screenshot 2 of 2

To get the list of workspaces for a user, just run the following command from the same prompt:

tf workspaces /owner:username


Figure 9: To list all workspaces for a specific user

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: