Summary: How can I determine TFS source control configuration for a local folder.
Explanation:
In our Software Factory I am creating CruiseControl.NET configuration files automatically based on the local folder where code from a source control system is living. I currently only want to support Subversion and TFS. Determining that Subversion is used as source control system, and determining the location of the repository is easy using the svn.exe info command, like shown in the PowerShell code below. But how can I do this when TFS is used?
One of the "problems" is that the currently logged-in user does NOT have access to the TFS server. We can't use integrated security because the dev machines are not domain-joined.
The closest I got was tf dir , I have to enter credentials in a popup box. Couldn't find command-line arguments to specify user and password. tf properties looks promising as well, but you must be authenticated to execute call. Subversion can provide info without authentication.
My current code in PowerShell with working code for SubVersion, the TFS code is missing;-)
Note that for the actual creation of the CruiseCOntrol.NET block we have a configured source control username and password available in global variables.
# # # # https://svn.mycompany.nl/svn/Acme.Intranet # # # # If under source control return a CruiseControl.NET source control configuration block in # the following format: # # https://svn.mycompany.nl/svn/Acme.Intranet # c:\project\Acme.Intranet.Build\WorkingDirectory\$configuration # acmebuild # acmepassword # #.Parameter configuration # Either "Debug" or "Release" # .Returns # A string with the configuration block, or $null if not under Subversion source control. ##> function GetSubversionSourceControlBlock { param ( $configuration ) $svn_exe = Join-Path -Path $productfolder -ChildPath "tools\DotNet2\svn-win32-1.5.2\svn.exe" $svnProductInfo = [xml](& $svn_exe info `"$productFolder`" --xml) $trunkUrl = $svnProductInfo.info.entry.url if ($trunkUrl -ne $null) { @" $trunkUrl $buildfolder\WorkingDirectory\$configuration $MastConfigurationGlobal_SourceControlUserName $MastConfigurationGlobal_SourceControlPassword "@ Verbose "Under Subversion source control. Trunk Url: $trunkUrl" } else { Verbose "Not under Subversion source control" $null } } # # tfs.mycompany.nl # $/Acme.Intranet # c:\project\Acme.Intranet.Build\WorkingDirectory\$configuration # acmebuild # acmepassword # #.Parameter configuration # Either "Debug" or "Release" # .Returns # A string with the configuration block, or $null if not under Tfs source control. ##> function GetTfsSourceControlBlock { param ( $configuration ) $null }
Best Answer
The story continues:
If you execute the tf command from a cmd prompt, everything goes as described in the previous answer. If you do it from a PowerShell command prompt you get the following:
It gives an error!
I have tried everything, but to no avail. I even tried it through the TFS object model, but that got really complex. To get the workspace for a local folder you need a name of the tfs server first. It is probably possible to iterate all currently mapped workspaces and iterate through the servers defined there (that is probably what tf.exe does) to test if the local folder belongs to that workspace.
I finally came up with the following solution:
I create a simple batch file ExecTfWorkprodCommand.bat wit the following code:
And I call this batch script from PowerShell. From the result I want to parse:
Example code on how to solve this: