Create local mapping on Team Foundation Services workspace using tf vc commands - tfs

I'm trying to create a local mapping to an already existing workspace using tf vc commands on the command prompt. Is this possible?

You can use Tf workfold command to realize the mapping. In the command option, there is /map option which specifies an association between a local folder and the Team Foundation version control server folder.
The syntax is as follows:
tf workfold [/map serverfolder localfolder] [/collection:TeamProjectCollectionUrl]
[/workspace:workspacename][/login:username,[password]
So the command is like the below:
tf workfold $/projects/MyTeamProject/* C:\LocalWorkfold\TeamProject
/map /collection:http://servername:8080/tfs/defaultcollection
/workspace:"WorkspaceName"
/login:username,password

Related

TFS Could not specify workspace when executing tfs get from the outside

I'm executing this command from location E:\app\
TFS.exe get "C:\Repo\" /recursive /noprompt /overwrite
in order to load latest changes from tfs to workspace inside C:\Repo\
and it's unable to determine workspace
Could not specify workspace. This can be improved by using the "tf workspaces /collection: TeamProjectCollectionUrl" command.
Unfortunely I cannot get it to work even with this suggested command
C:\Repo\>TF.exe workspaces /collection:url/Collection
Collection: http://url:8080/Collection
Workspace Owner PC Comment
-------------- ------------------- ---------- -------------------------------------------------------------------------
USER-PC USER USER USER-PC
You need to map the C:\Repo to the project before running command tf get C:\Repo from location E:\app. For example, I mapped $/CMMIProject to local folder D:\Workspace\TFS2018\CMMIProject:
Then the following command will work:
C:\Program Files (x86)\Microsoft Visual Studio 14.0>tf get D:\Workspace\TFS2018\CMMIProject

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.

TFS get <file> removes pre-existing local copies of <file>

I'm porting a legacy VSS-based build script to TFS. The script gets files from several server locations into different directories... to make this work with the same structure in TFS I frequently map & unmap specific working folders.
This seemed to work, until the script gets the same server file into two different local folders. Even though previous working folders are un-mapped, TFS moves the existing copy of the file rather than getting a second copy.
e.g:
cd dir1
tf workfold /map $/SOME_PATH .
tf get file.abc /all
tf workfold /unmap .
cd..\ dir2
tf workfold /map $/SOME_PATH .
tf get file.abc /all
tf workfold /unmap .
On line 7, I get "Replacing file.abc (moved from c:\dir1)" and end up with only one copy of file.abc.
I'm aware our process is not TFS-friendly but right now I just want it working so we can drop VSS, and then focus on re-structuring afterwards. Is there a way to stop this behaviour or a workaround I could use that doesn't totally change our process?
What I would do to get this working fast:
Cd Dir1
tf workfold /map $/SOME_PATH
tf get file.abc /all
Copy file.abc to temp location
tf workfold /unmap
cd..\ dir2
tf workfold /map $/SOME_PATH
tf get file.abc /all
Copy file from temp location to dir1
tf workfold /unmap
I don't think you can achieve this in TFS. if you remove a workspace mapping it'll remove the files. If you try to map the same file to 2 places you'll get an error.
You need to fix your build process. A short term solution might be to get the file once and then copy it to any other locationsit is needed. otherwise I think you need to bite the bullet and refactor your build process to be simpler. regardless of what systems you are using, simplifying you're build will help you in the long term.
I had the same problem and found no answer online so I figured out the solution and wrote up a blog post: http://www.softwarepronto.com/2013/09/getting-multiple-labels-from-tfs-using.html.
If you don't want to read the blog, the solution is to create the workspaces in different directories (see below):
MKDIR D:\ATest
CD /D D:\ATest
tf workspace /delete WorkSpaceATest /noprompt
tf workspace /new WorkSpaceATest /noprompt
tf workfold /map $/ATest D:\ATest /WorkSpace:WorkSpaceATest
tf get /version:LATest01
MKDIR D:\BTest
CD /D D:\BTest
tf workspace /delete WorkSpaceBTest /noprompt
tf workspace /new WorkSpaceBTest /noprompt
tf workfold /map $/BTest D:\BTest /WorkSpace:WorkSpaceBTest
tf get /version:LBTest01

Team Foundation Server switch between branches

Can we switch between branches in TFS
what i want is i downloaded a working copy and now I want to switch to different branch without downloading everything, because for large projects it will take lot of time since developers spend lot of time downloading
Is it possible, if not any workaround ??
You can switch branches from the command-line client (only downloading the differences) by changing your workspace mappings and using the /remap flag to the get command:
tf workfold /map $/Branch1 C:\Work
tf get C:\Work /version:T /recursive
tf workfold /unmap $/Branch1
tf workfold /map $/Branch2 C:\Work
tf get C:\Work /remap /version:T /recursive
In TFS branches are "physically" present in the Source Control, they're like "special folders". So you can totally choose what branch you get locally by targeting the right folder for your get.
If you have for instance:
Projects [folder]
ProjectA [folder]
Dev [Branch]
V1 [Branch]
ProjectB [folder]
Dev [Branch]
V1 [Branch]
and you want to get at the "Projects" level with only the content of "Dev", you can create mapping in your Workspace definition to cloack the V1 branches of ProjectA and B.
Just for supplementing the knowledge base - my colleague Isak Savo created useful batch for such purpose. You need to do some editing inside the script (at the top) to point to the correct source code location and appropriate branches. The core is basically the same as in Edward Thomson answer, but with some interactive logic added. I made some minor changes (directory context switching for tf commands, quotes for arguments - needed if there are spaces in directories) and shared it below:
#echo off
rem Command to switch the current source tree to a new branch.
rem It's best to not have any pending changes.
set DEVBRANCH=$/dir/src1
set RELEASEBRANCH=$/dir/src2
set SOURCEDIR=c:\sources directory\src
if exist "%SOURCEDIR%" goto ASK
echo Source code directory (%SOURCEDIR%) not found, please edit this script to point to the correct directory
pause
exit
:ASK:
set TARGET=
echo Available branches are:
echo Dev: %DEVBRANCH%
echo Release: %RELEASEBRANCH%
set /P ANSWER=Specify target branch? [Dev, Release]
cls
if /I "%ANSWER%"=="Release" set TARGET=%RELEASEBRANCH%
if /I "%ANSWER%"=="Dev" set TARGET=%DEVBRANCH%
if /I "%ANSWER%"=="quit" goto END
if [%TARGET%] NEQ [] goto SWITCH
echo "%ANSWER%" unknown, please answer Dev or Release. Specify quit to cancel
GOTO ASK
:SWITCH
rem Navigate to the mapping source folder to avoid "Unable to determine the workspace..." error while invoking tf commands.
echo Changing directory context
pushd %SOURCEDIR%
echo Switching to branch %TARGET%
echo - Creating new mapping...
tf workfold /map "%TARGET%" "%SOURCEDIR%"
echo - Get latest version...
tf get "%SOURCEDIR%" /remap /version:T /recursive
popd
goto END
:END
Save it e.g. to switch_branch.cmd and execute from any directory from your machine.
Team Explorer Everywhere has a "Switch to branch" command, which is probably what you're looking for.
Visual Studio, on the other hand, doesn't have the same command...
You can switch between multiple branches, as long as you are using same workspace and the working directory contains the branches.

Is there a bug in "tf add /recursive"?

I'm trying to add the following folder tree to TFS:
C:\TFS\folder1
C:\TFS\folder1\folder2
C:\TFS\folder1\folder2\folder3
C:\TFS\folder1\folder2\folder3\test.txt
In the above example the folder "C:\TFS" is a mapped TFS working folder. I issue the following commands from the console:
cd C:\TFS
tf add folder1 /recursive
After this command has finished my repository contains the following tree (as pending changes):
$/folder1
$/folder1/folder2
As you can see "folder3" and the text file "test.txt" below are completely missing! Why?
Update: I've submitted this as a bug to Microsoft:
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=423279
from microsoft the basic command goes as follows:
tf add itemspec [/lock:(none|checkin|checkout)] [/type:filetype]
[/noprompt] [/recursive] [/login:username,[password]]
I typed in the following command and it worked fine:
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\tf.exe" add itemspec /r "where to add to"
you run the command from the folder you want to copy files and in the command under "where to add to" you type the destination
worked for me.
c:\Temp>md Test\1\2\3\4\5
c:\Temp>dir test /s/b
c:\Temp\test\1
c:\Temp\test\1\2
c:\Temp\test\1\2\3
c:\Temp\test\1\2\3\4
c:\Temp\test\1\2\3\4\5
c:\Temp>cd test
c:\Temp\Test>tf add 1 /recursive
1
1:
2
1\2:
3
1\2\3:
4
1\2\3\4:
5
c:\Temp\Test>
In Tfs
Same if I do it from Test or above Test directory

Resources