TFS Workspace Cache - tfs

I appear to have some problems with my workspace cache. When I type:
tf workfold
In my workspace directory, I get the error:
Unable to determine the workspace
This article seems to imply that it’s a problem with the cache. Being cautious, I tried removing a single workspace:
tf workspaces /remove:WORKSPACENAME /server:servername
This seemed to work (that is, the command succeeds), because if I do it a second time it fails. However, when I issue:
tf workspaces
It still lists this workspace, and I still get the error.
Can anyone give me any guidance of the next step here? I assume what I’m deleting it the cache for the workspace and not the workspace itself, do I need to clear all my workspaces for this to work? If so, why might this make any difference?

Try running below command to refresh the cache:
tf workspaces /s:http://tfs-server:8080

this might be a daft question but are you running the tf workspaces command from a folder that's mapped to the workspace? e.g. your workspace mapping is something like $/MyTeamProject/Source -> c:\source
when you open your command prompt you should cd c:\source before running tf workspaces

You can try this one to delete the workspace:
tf workspace login:[your login credentials] - delete workspacename -collection:[collection URL]
example:
tf workspace login:US\\saket.kumar - delete saketworkspace1 -collection:https://tfs1101.client.com/tfs/CTS

Related

Exclude Files/Folder during TF get using command line

I have below mapped folder in local with TFS version control.
TFS version control folder ==> $/A/B/C
Local mapped folder ==> D:\MyFolder
Now from the command prompt, Getting all the latest files using below command
tf get D:\MyFolder /recursive /noprompt
Is there any way to exclude certain files/Folders while getting from TFS using the command line?
Thanks in advance
There isn’t ignore/exclude parameter in the tf get command line, but you can use specify the file/folder you want instead to use just get, for example tf get 314.cs.
In addition, you can cloak the files from the workspace: tf workfold /cloak (Team Foundation source control serverfolder|localfolder) [/workspace: workspacename] [/s:servername].
Another option - to ignore certain files you can add .tfignore file to the repository.

How do I get tf.exe to set the Source Control Folder to something other than the root?

So I am trying to script with TFS using the tf.exe command. I've looked at the docs but I can't seem to determine how to set the server path such that I don't get the intermediate path in my local directory.
E.g. The server has a dir that I want to get called $/Some/Depth/TargetDir and I want to put it in C:\MyFolder\StoreHere such that all files in TargetDir and all directories beneath it are stored in StoreHere.
Currently, I'm using tf get $/Some/Depth/TargetDir /recursive which results in the files in TargetDir to be downloaded, but in to C:\MyFolder\Storehere\Some\Depth\TargetDir which is not what I want.
I'm using TFS 2010.
Workspace mappings control where server paths are retrieved to your local paths. In the behavior you describe, you have a workspace mapping that resolves $/Some/Depth/TargetDir to C:\MyFolder\Storehere\Some\Depth\TargetDir.
Not having seen your actual workspace mappings, it's impossible for me to know exactly why, but this could be as simple as having a workspace mapping from $/ to C:\MyFolder\Storehere.
Instead, you need to map the actual directory you're interested in: you need a mapping from $/Some/Depth/TargetDir to C:\MyFolder\Storehere.
You will need to delete the existing, incorrect mapping first.
You could set this up in the Visual Studio Edit Workspace dialog, or you could use the command-line client:
tf workfold /unmap C:\MyFolder\Storehere
tf workfold /map $/Some/Depth/TargetDir C:\MyFolder\Storehere

Check if folder in TFS has changes in Command Line

Is it possible, through the command line (e.g. tf.exe) to check if there are new changes within a specific directory?
My hope is to have a script that will automatically merge certain folders if they have changes.
Have you checked Tf Command-Line Utility Commands on MSDN? Probably "Folderdiff Command" is what you want. Example
C:>tf folderdiff $/serverFolder F:\localFolder /recursive /noprompt

Command line "get latest" from TFS without mapping workspaces and such

I assume that this:
tf.exe get $/project /recursive
...needs this weird workspace mapping, known TFS server and such.
Is there any way I could do this simplest thing: go connect to this TFS server using this set of credentials, get latest source code for this project and put it here? All from the command line.
Firstly, are you wanting a copy of the controlled files that are no longer under source-control (such as a SVN export) or are you still hoping to work with the files and TFS?
Option 1: No Binding at all
If you simply want a copy of the latest files and no 'binding' to TFS, you're going to have to do a little work yourself. Leaving aside credentials ([/login:username,[password]] parameter to many command line methods).
Use the TF command to get a list of the files: tf dir "$/YourSolution" /Recursive > files.txt
Process files.txt with some clever batch file (or use a scripting language):
Read lines starting with $/ and this is the directory, create the directory in your destination (remove first three characters and the last character, a colon).
Read the next lines (until blank or end of file), each of these represents a file in the directory discovered in step 3. Assuming you have the file in a variable %file% and directory %dir%, then issue the following command (for each file in that directory):
tf view "$/%DIR%/%FILE%" "/output:Your-Target-Path/%DIR%/%FILE%"
or if you're happy with the current directory as the target:
tf view "$/%DIR%/%FILE%" "/output:%DIR%/%FILE%"
Note, you need the %DIR%/%FILE% in the output part or all files will be dumped in to the same directory.
NOTE: this is likely to a be VERY high bandwidth and slow operation!
Option 2: Temporary Mapping
Create a temporary workspace: tf workspace /new /collection:<URL_TO_SERVER> /permission:Private (note, this will prompt, there is a no-prompt option but determining a name for the workspace is left as an exercise)
Make a directory for files, e.g. LOCALDIR
Create a mapping for your folders: tf workfold /map "$/SERVER_DIR" "LOCALDIR"
Go into LOCALDIR
Get the files tf get . /Recursive
At this point you should now have all of the files and if you wanted you also have a binding with TFS so you could commit changes. Alternatively, you can now copy the content elsewhere and break the mapping/workspace. Using the correct command line variants of tf workfold /unmap and tf workspace /delete will unmap your workfolder and delete the workspace.
Export any folder cleanly from TFS? Finally found a brilliant solution I think.
I am not going to completely research this for you now, but intend to replace my incredibly messy build server workspace synch script with this later, when I get the time.
Solution:
Use Microsoft's Git-TF to get the source to disk without having to set up a workspace or anything. I tried the command, and it worked wonderfully. Think it will work for TFS 2010 and 2012. From what I can understand, there will be no bindings or workspaces or anything left behind that will cause problems later. I think all you need to install is GIT and GIT-TF.
http://www.microsoft.com/en-us/download/details.aspx?id=30474
You will actually get the files into a GIT repository, which is not a problem at all. You will get a (hidden?) folder named .git inside the folder you exported, and I guess you can simply delete it to get rid of any trace of GIT.
If someone implements this, which should be easy, please confirm it works as expected.
Quick solution
Building on Ray Hayes option 2 answer, I put together an actual script that should be straight forward to use for those who just want the quick and dirty solution. You should read his aswer for more info.
To use it:
Set the four variables to your working environment
remember that your
tf.exe might not be located in the same directory that I have it in,
especially if you are reading this from the future :)
.
SET COLLECTION_URL="http://localhost:8080/tfs/<collection>"
SET SERVER_DIR="$/<REMOTE_SOLUTION_DIR>"
SET LOCAL_DIR="X:\<YourLocalDir>"
SET TF_DIR="C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE"
%TF_DIR%\tf workspace /new /collection:%COLLECTION_URL% /permission:Private /noprompt tmp_batchws
%TF_DIR%\tf workfold /map %SERVER_DIR% %LOCAL_DIR%
cd /d %LOCAL_DIR%
%TF_DIR%\tf get . /Recursive
%TF_DIR%\tf workspace /delete tmp_batchws /noprompt
i wrote the powershell for the leading answer
$base = "f:\whereyouwantthefilestogo\"
foreach($l in get-content D:\outputfromTFdir.txt)
{
if($l -match '^\$.*\:$')
{
$repopath = $l.trim(':')
write-host 'base path'
$basepath = "$base$($l.Substring(2,$l.Length -3) -replace '/','\')"
if((Test-Path $basepath) -eq $false)
{
write-host 'making directory'
New-Item -ItemType directory -Path $basepath
}
continue;
}
elseif($l -match '^\$')
{
write-host 'sub folder'
$subfolderpath = "$basepath\$($l.trim('$'))"
if((Test-Path $subfolderpath) -eq $false)
{
write-host 'making directory'
New-Item -ItemType directory -Path $subfolderpath
}
continue;
}
elseif($l -match '.*\..*')
{
write-host 'get file'
$filename = "$basepath\$l"
write-host $filename
$repofile = "$repopath/$l"
tf view "$repofile" "/output:$filename" /collection:http://tfsserver
}
else{write-host 'blank line'}
}
There is no "easy" option when it comes to TFS command lines - they almost always involve an awful lot of typing (such as not being able to simply have a default set up so you don't have to specify a collection URL on every command)
The usual way to make TFS command lines "simple" is to write batch files to hide away all the details that have to be specified every time (server URLs and recurse flags etc)
TF.exe does allow you to do almost anything, though, so it is a pretty straight-forward sequence of tf calls to create a temporary mapping, do a Get and and delete the mapping again.
http://johannblais.blogspot.com/2014/07/tfs-equivalent-of-svn-export.html
http://tfs-server:port/tfs/Collection/TeamProject/Team/_api/_versioncontrol/itemContentZipped?repositoryId=&path=url-encoded-source-control-path
tfs-server is the TFS server hostname
port is the TFS port (usually
8080)
Collection is the name of your team project collection
TeamProject is the name of your team project
Team is the name of the team
url-encoded-source-control-path is the URL encoded source
control path (for example, $/Project1/Main/Sources/Folder/SubFolder becomes %24%2FProject1%2FMain%2FSources%2FFolder%2FSubFolder

Jenkins: How To Build multiple projects from a TFS repository?

I have set my workspace directory to C:\jenkins_builds\workspace and I want to build ProjA and ProjB, each having a local workfolder (same as project name).
When fetching the source code from my repository, the first two things the TFS plugin does are:
tf workspace -new %workspace-name-A%;%user-name% -server:%my-server%
tf workfold -map $%branch% ProjA -workspace:%workspace-name-A% -server:%my-server%
Which goes fine when building ProjA. The problem is, the first command maps the root directory from the repository directly to my C:\jenkins_builds\workspace directory. The second command does what I actually want, i.e. mapping %branch% to the ProjA subfolder. Later on, when building ProjB, the first command fails (and consequently the build) with the following error message:
The path C:\jenkins_builds\workspace is already mapped in workspace %workspace-name-A%;%user-name%.
OK, it seems like a bad idea to map the root directory to the work directory. But why does this automatically happen when the TFS plugin runs the workspace new line? Currently I have to clean things up between building ProjA and ProjB by running the -unmap command.
My team is using Team Foundation 3.0.
We have the same situation and there are 2 ways to solve this:
use different workspace-root-directories for the two builds
This results in the need for two checkouts => double the space and slower, but better isolation between the two builds
"hardcode" the workspace name to the same for both builds
By default jenkins creates a workspace containing the build name, which can be changed in the "advanced" section of the TFS config, and then you can use the same workspace-/workfolder-mapping for several builds - in our case we called them ProjectName_${NODE_NAME} so it even works on several nodes

Resources