I want to be able to set up a semi automatic Build script to check out a specific commit from our TFS server to a non generic folder to then cause the code to be built and packaged to enable a release.
I understand how to use the command line, and can script it fine, but its how to create a temporary workspace that will not interfere with the existing workspace on the machine to check the code out into.
I will have to research how to build the solution as well from the commandline but that may not be as hard as this...
You can use the command line tool tf.exe to create a new workspace e.g.:
tf workspace /new workspace_name`;username /collection:http://myserver:8080/tfs/DefaultCollection
You can get work folder mappings by using a template when creating the new workspace. See the /template parameter on tf workspace. Or you can use the tf workfold /map command to create work folder mappings for the new workspace. When you're done, use tf workspace /delete to delete the workspace.
Related
Is there a command (or series of commands) to sync a TFVC workspace with the server, ensuring that what's on disk exactly matches what's checked in to the server.
tf vc scorch almost does what's needed, in that it syncs the client workspace with the server's version of that workspace, but if a new item's been created on the client and added to source control, though not yet checked in, that item remains after scorch is run. NB: I'm using the TF Client version of scorch rather than the power tools version, as I'm working with VS2017 (scorch is supported from VS2013 SP1), should that make any difference.
Related, I'm aware that power tools includes a treeclean command; however that only impacts items not under source control; not those added to version control but not checked in. https://adamprescott.net/2011/09/12/clean-tfs-workspaces-with-scorch-treeclean/.
The only way I can think of to achieve this is to delete (tf vc workspace /delete /collection:"https://$MyInstance.visualstudio.com/DefaultCollection" $MyWorkspace) & recreate (tf workspace /new $MyWorkspace /collection:"https://$MyInstance.visualstudio.com/DefaultCollection") the workspace, before running a recursive get to repopulate the new folder. However, that feels like the long-way-round for something which I'd assume would be simple...
We're using TFVC rather than Git because we're working with Dynamics AX, which does not natively support Git.
The reason I want to delete such objects is because this script will run on a build server, where I want to ensure we build exactly what's checked in to source control. Whilst in theory no one should be creating new objects on the build server, I don't like to rely on that assumption / want to make this script as robust as possible.
I'd missed the undo command: TF.exe vc undo * /recursive /noprompt.
Running this command before running get and then scorch ensures that my workspace exactly matches the latest server version.
Here's the complete code used to sync the current workspace with the server. NB: This command assumes that tf.exe's directory is included in the path environment variable (or you can replace tf with "...\path\to\tf.exe"), that the current/working directory is mapped in source control, and that your tf credentials are cached (otherwise include the /login argument with username and password). I've not included /all, '/overwrite', or '/force' on the get command, since scorch will cover this anyway; the main purpose of the get here is to ensure our workspace is "pointing at" the latest definition.
tf vc undo * /recursive /noprompt
tf vc get * /recursive /noprompt
tf vc scorch * /recursive /noprompt /diff
NB: The vc above is superfluous / just ensures that were there a possibility for ambiguity the system would know to use tfvc's version of the command instead of the git version.
When I delete a file in the file system, TFS 2013 will correctly show it as still being in version control, but the file will not show as pending delete, and committing changes does not remove the file from the server. If I go to Source Code Explorer, the deleted file shows up as being on the server, but if I try to delete it, I get an error saying The item could not be found in your workspace, which is also correct, but I need to delete the file and I can't find any way to do it. I really do NOT want to have to download each file and manually delete it.
So, how can I get TFS to detect files that are no longer on the local file system and remove them from the server?
Note, my workspace is local, not server. Many sources say that TFS should detect local deletes in a local workspace, but this does not seem to be true, at least, it's not what I'm seeing.
Update: I know that my workspace is local because here's the TFS Workspaces window:
If the changes are not being detected then your workspace is currently configured as a Server Workspace and not a Local Workspace.
If you edit your workspace, click Advanced, and switch the workspace type to Local.
Note: You can check the configuration by looking for the hidden $tf folder in the root of your workspace...
Use /deletes with the tfs power tool: http://blogs.msdn.com/b/buckh/archive/2005/11/16/power-toy-tfpt-exe.aspx#Online
I am trying to write a Powershell script where I may need to checkout items into different workspaces. How can I specify in the tf command which workspace to use?
Your best option is to use the tfs workspace command and create a new 'temporary' workspace while your ps script executes.
This only requires you to know the tfs path, you can then map to a local folder and only work with the files you need. At the end of the script you can delete the workspace.
Tfs workspace command
http://msdn.microsoft.com/en-us/library/y901w7se(v=vs.100).aspx
I need a batch script that uses tf to retrieve the directory structure for a label in TFS, something like the equivalent of svn export, while not messing up with my current working workspace.
This is what I managed to come up with:
tf workspace /new TemporaryWorkspace /noprompt
This will create a new workspace, but with the following working folder:
$/: C:\
(considering that I ran the command from C:)
This is not what I want, but "tf workspace /new" doesn't seem to allow specifying the mapping, so I ran this to remove the default mapping:
tf workfold /unmap $/ /workspace:TemporaryWorkspace
then this one to create my desired mapping.
tf workfold /workspace:TemporaryWorkspace /map $/Project/Path C:\Temp\Path
Change the current directory to the local working folder (I don't know of another way to select the current workspace)
PUSHD C:\Temp\Path
Now I can finally retrieve the label and do my stuff with it.
tf get /version:LMyBeautifulLabel
Now the clean up.
tf workspace /delete TemporaryWorkspace /noprompt
Go back
POPD
All these seems a bit too cumbersome for my humble purpose. Is there a simpler way?
Thanks.
Unfortunately, you will need to create a workspace with the proper working folder mappings and then run the get. There's no one-liner alias to set this up for you.
You may be able to get by with creating a longer-lived workspace with the proper working folder mappings that you need not delete, but certainly if you're using this workflow frequently but with different labels or in different locations, creating a new temporary workspace each time probably does make the most sense.
Your best solution here is to either create a command script that executes this workflow or use the little known script functionality of the tf command line client. You can run a tf script by using:
tf #<filename>
or simply using:
tf #
to read from standard input.
Is it possible to just say to TFS that I have a file (call it Version.txt) and I want it to be checked in at a location (say $/MyProject/MyVersionLocation) and not have any workspace setup for that location?
Something like (pretend Syntax):
tf.exe c:\Version.txt CheckIn $/MyProject/MyVersionLocation /WorkSpaceOverride
If so, how do you do it?
It is not possible to checkin a file without a workspace mapping for that path.
One option would be to use a combination of "tf workspace" and "tf workfold" to dynamically create a workspace before checking in.
For example:
tf workspace /collection:http://server:8080/tfs/Collection /new TempWorkspace /noprompt
tf workfold /collection:<server> /workspace:TempWorkspace /map $/MyProject/MyVersionLocation/Version.txt C:\Version.txt