Adding items in bulk to Azure DevOps using tf commandline - tfs

ers,
One of our products depends on third party software that we receive monthly updates for. The received software contains a variety of files and binaries in a complex folder structure containing around 100-150K files. We need to add new items to our version control so we can include it in our build pipeline.
We run over the entire folder structure via a Powershell Script and execute "tf.exe add file" for each (relevant) file. This currently takes around 14 hours. We've made it multi threaded but that doesn't seem to affect the processing time a whole lot. "tf.exe add"-commands just take their time and don't run concurrent from what we can tell.
TF.exe add fileOne.dll
TF.exe add fileTwo.png
We also tried optimizing it handle multiple files in one command
TF.exe add fileOne.dll fileTwo.png
But haven't been able to get this to work. According to the docs you can specify multiple files
itemspec - Specifies the scope of the items to add. You can specify more than one
itemspec argument
But TF.exe errors out on us
TF.exe: C:\workfolder\fileOne.dll fileTwo.png : no file matches.
To my questions:
Why isn't it letting us add multiple files/itemspecs with "tf.exe add"?
Is there a more efficient way to make this process, bulk adding files to DevOps, faster?

The itemspec is a glob format and explained here.
You can use multiple item specs, but each must be prepended with the path (or be rooted in the current directory), so either:
tf vc add C:\workfolder\fileOne.dll C:\workfolder\fileTwo.png
Or
c:
cd workfolder
tf vc add fileOne.dll filetwo.dll
tf vc add .\fileOne.dll .\filetwo.dll | equivalent of the above
But if what you're trying to do is adding all files in a specific folder when needed, then the wildcard option combined with /recursive is your friend:
tf vc add c:\workfolder\* /recursive
To further speed up the process, you can switch to a Local Workspace, in that case the tf vc add command won't need to talk to the server to prepend the change, it is only registered locally. Then the checkin command will be able to send the whole batch of changed files in bulk to the server.
You can switch the workspace with the following command:
tf vc workspace /location:local

Related

Checkin multiple files with tf.exe in one changeset

On one of our builds we are kicking off some automated process which is checking out and checking in some files automatically.
This all works rather well, but at this time we are running the checkin command which looks like the following
tf.exe checkin /force /comment:"foo" /noprompt /bypass /override:"bar"
All of the files with a Pending status will get checked in.
I'd like to make this script a bit more specific and only checkin the files (2 in total) which we actually change during the build, so we know for sure no files will get checked in 'by accident'.
I've already seen we can specify a single filename with the checkin command, but doing so we will get 2 different changesets in TFS, instead of 1. We would really like to have 1 changeset, containing both changed files as the changes belong to eachother.
Any ideas on how to approach this?
Minor addition / Short term solution
For the moment I've solved our 'problem' by specifying the folder where our modified files are located, which kind of looks like this
tf.exe checkin "/my/folder/location/" /recurse /force /comment:"foo" /noprompt /bypass /override:"bar"
Note the folder location and the /recurse parameter added.
You simply separate the files by spaces:
tf.exe checkin file1.ext file2.ext /force /Comment:"foo" /noprompt /bypass /override:"bar"
The documentation is not clear about this point but it might be a general specification of an itemspec that it can be multiple items.
See similar question about checkout: Is there a way to check-out multiple files from various folders in TFS in a single operation
As mentioned by others you might run into problems with the command line being longer than the system supports, in which case you might need to look at other solutions.
cmd.exe has a limit on how long a command can be. Using the version control API, or simply 'tf checkin /i' (no arguments) is likely to be a better choice than passing lots of long filenames.
It's normal if a file becomes automatically checked out due to a change, and if ultimately the contents of the file are changed back to it's original state. At that point you would see the message about identical contents upon comparison. You could also use tfpt uu /noget /r * command to ignore Files which are identical to the originals. You'll need to have TFS Power Tools installed for this to work. Note: there is no TFS Power tool 2017.
For more details please refer below two links:
Visual Studio TFS shows unchanged files in the list of pending changes
Can TFS Pending Changes show files that are truly changed like SourceGear Vault?

TF diff entire set of files at once rather than one at a time

When I run tf diff, either recursively or against a shelveset, it goes through file-by-file and runs tf diff <myItemSpec>. I have my diff config set to compare files using windiff.exe which can handle a list of files, so running a new instance of windiff for every file is really annoying.
I remember being able to run windiff against an entire set of files at once years ago, but when I was working on that project, we were using two different versioning systems (originally our project was in TFS and we transitioned back to a proprietary versioning system, one that I'm certain had this functionality), so maybe TFS never could do this.
tf folderdiff seems like it should be the answer, but it doesn't appear that you can set the program it runs, nor can you specify a shelveset. It just runs some TF GUI which then allows you to run your configured diff program on a single file at a time.
Am I remembering wrong and TF never could do this? Is there there a hack/script that can do what I want it to?
As here, https://stackoverflow.com/a/2166188/616827,
tf diff $/Foo /version:C14317~C14318 /recursive /format:unified >
foo.diff
$/Foo specifies the entire repo (not one file at a time)
/Version to compare one changeset against the previous
/format is optional

TFS 2010 - bulk checking out of just .html files this time... How?

I need to bulk-check-out of all our .html files.
(to do a masse edit-replace from the command-line, and check them all back).
This is just a one time thing. I see a lot of threads on how to exclude files types but at project inception and definition level, like
Team => Team Project Collection Settings => Source Control File Types
or for TFS 2012 the .tfignore file.
But..
1) This seems to be for permanent exclusion at the project level. I don't want to touch the overall Source Control settings, colleagues work with all these other files types I need excluded.
2) These filters are all defined by what you exclude. But it would be much easier in that case, to define what you want to include (here .html files), so in essence, to say include 'A', instead of having to say exclude 'B', exclude 'C', exclude '...' going after the whole alphabet.
Thank you
For a bulk checkout, you can use tf checkout.
Open a command prompt with the current path within your local workspace and issue this command to check out all .html files:
tf checkout *.html /recursive
If you want to limit the checkout to part of the source tree, specify that in the itemspec:
tf checkout $ProjectCollection/Trunk/Project/*.html /recursive
If you are using TFS 2012 or newer, just make sure you are using a local workspace and you don't need to explicitly check-out anything. TFS will automatically detect local changes and put them in the Pending Changes list.
So just run your tool locally to go and bulk change all the html files. Then fire up VS and look in the Pending Changes window, all changed files should be listed and can be checked in.

Is there a way to check-out multiple files from various folders in TFS in a single operation

Is there a way to check-out multiple files from various folders in TFS in a single operation.
i have modified multiple files under muliple direcotries but i want them to check-out in a single click and check-in also in single click.
Thanks.
Yes, using the TFS command line client (tf.exe).
If you have tf.exe available, you could do this using the checkout command. (If you don't, take a look at this question: How to get tf.exe (TFS command line client)?)
Checkout command for Visual Studio 2013-2015: https://www.visualstudio.com/en-us/docs/tfvc/checkout-or-edit-command
Older versions: https://msdn.microsoft.com/en-us/library/1yft8zkw(v=vs.80).aspx
Example: Separate multiple files by spaces
tf checkout file2.cs file2.cs
Example: Use a wildcard to search
tf checkout *.csproj /recursive
Yes, in the solution explorer hold down the control key as you select files and them check them out all at once.

tfs: how to unlock changes

I originally edited a file, which did a checkout. I received a new computer, and now I want to edit the file. I don't care about the original edit.
TFS reports that another user has an exclusive lock on the file. It's not actually another user, it's me, but the machine is different, so the workspace is different.
I tried unlocking with the tf commandline using the following command:
tf lock /lock:none /workspace:oldmachinename;domain\me /recursive $/projectname/directory /s:http:tfs:8080/tfs/project
I get no errors, but when I go into Visual studio 2010 (We're using tfs 2010 as well) The files remain locked.
What am I doing wrong?
Have you tried using TFS powertools?
Once you have that, you can right-click on your folder or file, and choose Find in Source Control -> Status. After you click Find, it should show you all the check-outs, or files that are checked-out
You should then be able to right-click on the checkout and choose "Undo..".
While this is generally issuing the same command line arguments, I've had good luck with it.
Deleting the old workspace is probably what you want to do. You can do this with the tf workspace command, but an easier method is to use the free TFS Sidekicks add-on which gives you a GUI to manage and delete workspaces.
If you aren't intending to use the old workspace again, it would be a good idea to (carefully) delete the entire workspace. This will clean up everything relating to it, and mean that it no longer "pollutes" listings of your active workspaces, etc.
You can also break the lock on a single file, but you will need to have appropriate permissions to be able to break locks. See here for a specific explanation of how to do it.
Try something like this:
The following example unlocks and makes all files in the src/ Team Foundation version control server folder available for check-out and check-in by other users.
c:\projects>tf lock /lock:none src/
More documentation here:
http://msdn.microsoft.com/en-us/library/47b0c7w9.aspx

Resources