Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#365485 - 08/12/2015 21:49 Automatically locating where the dev stores his source code?
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31578
Loc: Seattle, WA
This is a really off-the-wall thing. But if there is a way to do this, then the Empegbbs will be able to find it. If we can't find it, it doesn't exist, right?

Each time a developer in the company sets up a new install of Visual Studio on a new machine, and then connects to Team Foundation Server (TFS) to connect to the source code tree and synch up to the latest source code, she can choose where on her hard disk to store that source code, even possibly inventing a new directory in the process.

Maybe she puts it in c:\Source\ or maybe in c:\Development, or maybe in C:\Projects, or maybe she took the default settings and put it in c:\users\HerUserName\Source\Workspaces\ProjectName. My point is, everyone on the team will have that source code located in a different hard disk folder, depending on whose dev machine you're looking at. It's completely arbitrary.

Yet Visual Studio, and especially its plugins for Team Foundation Server, have no trouble automatically finding this location once it's been established. So that location must be stored in a config somewhere.

Does anyone know where this is stored? I have some utilities which run "outside" the Visual Studio environment, but they need to act upon files found within that source code tree, and I don't want the utilities to have to prompt the user for the location of those source code files.

In cases where a relative path from within the development tree works, I have made them work that way. But some of these run completely outside that structure and I want them to discover where the top of that structure exists.

Any ideas?

I've looked for an existing environment variable for this and there doesn't seem to be one.
_________________________
Tony Fabris

Top
#365486 - 08/12/2015 21:55 Re: Automatically locating where the dev stores his source code? [Re: tfabris]
peter
carpal tunnel

Registered: 13/07/2000
Posts: 4174
Loc: Cambridge, England
Surely Visual Studio only knows where the project is, while the project file is open. What would happen if the developer had two different checkouts?

Peter

Top
#365487 - 08/12/2015 21:56 Re: Automatically locating where the dev stores his source code? [Re: tfabris]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3583
Loc: Columbus, OH
I'm assuming you've searched the registry for that specific path?
_________________________
~ John

Top
#365488 - 08/12/2015 23:00 Re: Automatically locating where the dev stores his source code? [Re: peter]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31578
Loc: Seattle, WA
Originally Posted By: peter
Surely Visual Studio only knows where the project is, while the project file is open. What would happen if the developer had two different checkouts?


I'm talking about at the "Source Control Explorer" level. Above the project/solution level.

If the dev has more than one checkout, the source control explorer knows about them. I guess I'm looking for its knowledge.
_________________________
Tony Fabris

Top
#365489 - 09/12/2015 00:21 Re: Automatically locating where the dev stores his source code? [Re: JBjorgen]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31578
Loc: Seattle, WA
Originally Posted By: JBjorgen
I'm assuming you've searched the registry for that specific path?


Yeahhhh... surrrrrre....

*quickly searches registry*

Visual studio has a "default open project" location and a "last opened solution" location, and of course it shows up in a bunch of MRU lists... not what I'm looking for because those can change independently of the synched source code location.

I wonder how TFS+Source Control keep track of their local mappings for a given user. That's what I'm really looking for.
_________________________
Tony Fabris

Top
#365490 - 09/12/2015 00:55 Re: Automatically locating where the dev stores his source code? [Re: tfabris]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31578
Loc: Seattle, WA
Hmm. There seems to be something here. Ish.

C:\Users\UserName\AppData\Local\Microsoft\Team Foundation\6.0\Cache\Volatile\SomeBigGUIDnumberHere_https\VersionControl.config
_________________________
Tony Fabris

Top
#365491 - 09/12/2015 03:48 Re: Automatically locating where the dev stores his source code? [Re: tfabris]
drakino
carpal tunnel

Registered: 08/06/1999
Posts: 7868
I don't know how TFS handles this, but I do know TFS is a fork of an old Perforce release.

Perforce has a command "p4 where". If you provide it a depot path, or a local file system path, it will return the depot path, local file system path, and local workspace mapping path.

This information was all held server side. It's possible this is true for how TFS handles it too based on it's legacy of being an old Perforce derivative.

Looking at the TFS command list, "tf properties" looks to provide some options that may work like p4 where.
https://msdn.microsoft.com/en-us/library/tzy14b58(v=vs.100).aspx

Top
#365494 - 09/12/2015 18:37 Re: Automatically locating where the dev stores his source code? [Re: drakino]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31578
Loc: Seattle, WA
"TF.exe Properties" (or its less-deprecated version, "TF.exe info"), did not work, however, you got me headed in the right direction, and a slightly different parameter worked.

The command we were looking for was:

TF.EXE WORKFOLD

That's the command to display all working folder mappings that the user has in TFS. Works perfectly, gets me exactly the information I wanted.

THANK YOU!
_________________________
Tony Fabris

Top
#365495 - 09/12/2015 19:34 Re: Automatically locating where the dev stores his source code? [Re: drakino]
Roger
carpal tunnel

Registered: 18/01/2000
Posts: 5682
Loc: London, UK
Originally Posted By: drakino
I don't know how TFS handles this, but I do know TFS is a fork of an old Perforce release.


I think that's a myth.

Microsoft used to (and some teams probably still do) use an internal tool called Source Depot, which definitely was a fork of Perforce. I've seen this confirmed in a couple of MS blogs, and, anecdotally, I've used both.

I can't find any evidence that TFS is derived from that codebase.

However, I can believe that TFS uses a bunch of paradigms from Source Depot (and hence from Perforce), because that's what the developer division at Microsoft were used to.
_________________________
-- roger

Top
#365496 - 09/12/2015 19:35 Re: Automatically locating where the dev stores his source code? [Re: tfabris]
tfabris
carpal tunnel

Registered: 20/12/1999
Posts: 31578
Loc: Seattle, WA
Implemented as a full batch file example:

Code:
@echo off

:: -----------------------------------------------------------------------------------
::  Demonstration of how to get user's local folder mapping of a TFS Code tree
:: -----------------------------------------------------------------------------------

	CALL :GetLocalFolderMapping $/WorkSpaceName/FolderName
	
	echo:
	echo ------------------------------------------------------------------------------
	echo Local folder path is:
	echo:
	echo "%LocalFolderPath%"
	echo ------------------------------------------------------------------------------

:: -------------------------------------------------------------------------------------------------------------------
::   Finish up
:: -------------------------------------------------------------------------------------------------------------------
:VeryEnd
	
	pause
	exit 0

goto:eof


:: -----------------------------------------------------------------------------------
::  Subroutine to get local folder mapping of logged-in-user's synched TFS code tree.
:: -----------------------------------------------------------------------------------
:GetLocalFolderMapping

	:: -----------------------------------------------------------------------------------
	::  Usage:
	::        CALL :GetLocalFolderMapping $/WorkspaceName
	::        CALL :GetLocalFolderMapping $/WorkspaceName/FolderName
	::
	::        Then do something with the variable %LocalFolderPath%, such as:
	::             Copy "%LocalFolderPath%\MainSolutionFile.sln" c:\temp\backup.sln
	::
	::  Details: 
	::
	::  Queries Team Foundation Server with the TF.EXE command line utility that is shipped
	::  with Visual Studio to ask what the local folder mapping is for a particular server
	::  code tree workspace. For example, if you have a source code tree on the server of,
	::  for example, $/SendBus/Development, and you need to programmatically determine what
	::  the current user's local mapping of that folder is (for example, if you need to
	::  perform a file operation on one of the files in the local folder and you need to
	::  know its local hard disk location), then you can run this program to find the
	::  local folder name that is mapped to that server-side TFS directory name.
	::
	::  Requires:
	::    - User is logged in and has permissions on TFS.
	::    - User has a fairly recent version of Visual Studio installed
	::    - You need to know the server's name for the mapping.
	::    - The user must have already mapped that thing.
	:: -----------------------------------------------------------------------------------

	:: Which workspace do we want to know the local folder mapping for?
	:: User must already have a mapping for this in their TFS configuration.
	:: This workspace is supplied as the %1 parameter to the call to this subroutine.
	set WORKSPACE=%1

	:: Save off the current directory folder, because we are going to change it and we want to
	:: change it back after we're done.
	PUSHD
	
	:: Locate latest version of Visual Studio on user's hard disk.
	:: Search for multiple possible versions of VS in user's program files folder.
	:: This will use the highest-alphabetical version it finds in the Program Files folder
	:: by simply looping through all of them and doing a SET command for each one, the last one
	:: it finds is the last SET that sticks.
	for /d %%a in ("%ProgramFiles(x86)%\Microsoft Visual Studio*") do set "LatestVS=%%~a"
	
	:: Verify that it located at least one version of Visual Studio, quit if not.
	IF "%LatestVS%"=="" CALL :ErrorMessage "Could not locate an installed instance of Visual Studio."
	
	:: CD to that location.
	echo Visual Studio found: %LatestVS%
	cd /D "%LatestVS%"
	
	:: CD to the common folder, then to the IDE folder beneath that.
	cd common*
	cd IDE
	
	:: Make sure that there is a TF.EXE in this location, quit if not.
	IF NOT EXIST TF.EXE CALL :ErrorMessage "Could not locate TF.EXE in the Common*\IDE folder under %LatestVS%."

	:: Call TF.EXE with the parameters to locate what we are looking for.
	:: Display the query to the screen so that if there is an error the user will see it.
	echo Querying TFS for local working folder of %WORKSPACE%
	TF.EXE WORKFOLD %WORKSPACE%
	echo:
	
	:: Do the query again, but this time pipe it through a command which will filter out the one variable we really want.
	:: The output looks like this:
	:: 		===============================================================================
	:: 		Workspace : SOMENAME (User Name)
	:: 		Collection: https://my.tfsserver.com/tfs/SomeName
	:: 		$/WorkSpaceName/FolderName: C:\Users\UserName\Source\Workspaces\WorkSpaceName\FolderName
	::
	:: so, skip to the 4th line and get the second 'token' on that line, which is the local path.
	::
	FOR /f "skip=3 tokens=2" %%a IN ('TF.EXE WORKFOLD %WORKSPACE%') DO set LocalFolderPath=%%a

	:: Verify that we actually got a local folder mapping, error out if not.
	IF "%LocalFolderPath%"=="" CALL :ErrorMessage "Could not locate a local folder mapping for %WORKSPACE%."

	:: Before exiting the subroutine, set the current directory folder back to what it was before we started.
	POPD
	
	:: Environment variable %LocalFolderPath% now contains the user's local mapping of %WORKSPACE%
	:: After returning from this subroutine, use the variable %LocalFolderPath% as you see fit

goto:eof

	
:: -------------------------------------------------------------------------------------------------------------------
::   Error Routine, exit program with a message.
::
::   Parameter: The error message.
:: -------------------------------------------------------------------------------------------------------------------
:ErrorMessage

	echo:
	echo:
	echo ----------------------------------------------------------------------------
	echo An error occurred:
	echo %1
	echo ----------------------------------------------------------------------------
	echo:
	pause
	exit 1

goto:eof
_________________________
Tony Fabris

Top
#365497 - 09/12/2015 19:54 Re: Automatically locating where the dev stores his source code? [Re: Roger]
drakino
carpal tunnel

Registered: 08/06/1999
Posts: 7868
Originally Posted By: Roger
However, I can believe that TFS uses a bunch of paradigms from Source Depot (and hence from Perforce), because that's what the developer division at Microsoft were used to.

I could see that, and likely my mind has blurred some past discussions a bit. Worked with both a former project manager and and former engineering lead from the developer tools side of Microsoft. Our discussions were usually mixed with cursing some code merge pains from the Unreal engine during crunch times on DC Universe.

I do remember both of them were happier with the tools Perforce had at the time, TFS was in it's infancy and having some growing pains. The former PM quickly backed off his plans to switch the studio to TFS when he realized in that era it wasn't suitable for large game development. I've heard it's improved a lot, which is also the case for Perforce compared to where that old Source Depot fork happened.

Top