Version control 如何比较跨TFS项目的源代码

Version control 如何比较跨TFS项目的源代码,version-control,tfs,Version Control,Tfs,我们有许多遗留项目最近添加到TFS版本控制中。现在我们面临的问题是,我们的每个项目都包含公共代码的副本,这些代码已分别修改和维护 是否有方法将TFS中一个解决方案的源与同一TFS服务器上另一个解决方案的源进行比较?-我可以指定要比较的文件夹和文件 由于解决方案的规模和性质,目前无法重组存储库或对SolutionsN进行重大重构 我还对任何可能使这个过程自动化的API感兴趣 谢谢 c:\temp>tf folderdiff/ TF - Team Foundation Version Control

我们有许多遗留项目最近添加到TFS版本控制中。现在我们面临的问题是,我们的每个项目都包含公共代码的副本,这些代码已分别修改和维护

是否有方法将TFS中一个解决方案的源与同一TFS服务器上另一个解决方案的源进行比较?-我可以指定要比较的文件夹和文件

由于解决方案的规模和性质,目前无法重组存储库或对SolutionsN进行重大重构

我还对任何可能使这个过程自动化的API感兴趣


谢谢

c:\temp>tf folderdiff/

TF - Team Foundation Version Control Tool
Copyright (c) Microsoft Corporation.  All rights reserved.

Displays a visual representation of the differences between files in two server
folders, in a server folder and a local folder, or in two local folders.

tf folderdiff [sourcePath] targetPath [/recursive] [/noprompt]
              [/server:serverName:port] [/filter:filter]
              [/filterLocalPathsOnly]
              [/view:same,different,sourceOnly,targetOnly]
C:\temp>tf folderdiff 1 2/无提示

===========================================================================
Items That Exist Only in C:\temp\1
===========================================================================

C:\temp\1\baz

===========================================================================
Items That Exist Only in C:\temp\2
===========================================================================

C:\temp\2\bar

===========================================================================
Show Items That Have Different Contents
===========================================================================

C:\temp\1\quux - 
    C:\temp\2\quux

===========================================================================
Summary: 1 folders, 4 files, 1 source, 1 target, 1 different, 0 with errors
===========================================================================
编辑:如果不明显,默认视图为sourceOnly+targetOnly+different。我有一个名为“foo”的文件,两个文件夹中的内容相同

我意识到命令行工具本身不是API,但不幸的是,它是这里的最佳选择。否则,您需要自己爬树——版本控制API中没有文件夹差异。你得到的只是一个15+个对单个项目进行操作的混乱方法

另一方面,如果要比较的所有文件都要签入,这意味着您可以进行计算,而无需任何昂贵的磁盘I/O(TFS存储每个文件内容的哈希)。快速Powershell示例:

function Compare-TfsDir([string] $dir1, [string] $dir2, [switch] $includeEqual)
{
    $dir1 = $dir1.ToLower()
    $dir2 = $dir2.ToLower()    
    filter Decorate($dir) 
    { 
        $_ | add-member noteproperty RelativePath $_.ServerItem.ToLower().Replace($dir, "") -passthru |
             add-member noteproperty HashString ($_.HashValue | %{ "{0:X2}" -f $_ } | join-string) -passthru
    }

    $items1 = $tfs.vcs.GetItems($dir1, $tfs.VCS_RecursionType::Full).Items | Decorate $dir1
    $items2 = $tfs.vcs.GetItems($dir2, $tfs.VCS_RecursionType::Full).Items | Decorate $dir2  

    $dirComp = compare -IncludeEqual -Property RelativePath $items1 $items2    
    "---Tree Comparison---"
    $dirComp | ? { $_.SideIndicator -ne "==" } | ft -auto RelativePath, SideIndicator

    $both = $dirComp | ? { $_.SideIndicator -eq "==" } | % { $_.RelativePath } | Linq-ToSet    
    filter InBoth { if ($both.Contains($_.RelativePath)) {$_} }
    $contentComp = compare -inc:$includeEqual -Property HashString, RelativePath `
                           ($items1 | InBoth) ($items2 | InBoth)

    "---Content Comparison---"
    $contentComp | ? { $_.SideIndicator -ne "<=" } | ft -auto RelativePath, SideIndicator
}    
函数比较TfsDir([string]$dir1,[string]$dir2,[switch]$includeEqual)
{
$dir1=$dir1.ToLower()
$dir2=$dir2.ToLower()
过滤器($dir)
{ 
$124;添加成员noteproperty RelativePath$124;.ServerItem.ToLower().Replace($dir,“”)-passthru|
添加成员noteproperty HashString($_.HashValue |%{{{0:X2})-f$_}|连接字符串)-passthru
}
$items1=$tfs.vcs.GetItems($dir1,$tfs.vcs_RecursionType::Full)。Items |装饰$dir1
$items2=$tfs.vcs.GetItems($dir2,$tfs.vcs_RecursionType::Full)。Items |装饰$dir2
$dirComp=compare-IncludeEqual-Property RelativePath$items1$items2
“---树比较--”
$dirComp |?{$|.SideIndicator-ne“=”}| ft-自动相对路径,SideIndicator
$both=$dirComp |?{$\.SideIndicator-eq“=”}{$\.RelativePath}{$\.Linq-ToSet
在两个{if($both.Contains($\u.RelativePath)){$\u}中进行筛选
$contentComp=compare-inc:$includeEqual-Property HashString,RelativePath`
($items1 | InBoth)($items2 | InBoth)
“--内容比较--”

$contentComp |?{$\ SideIndicator-ne“您的代码不工作。例如:linq ToSet不是cmdlet。