如何枚举具有待更改的源文件列表并获取其服务器位置?

时间:2010-07-14 22:42:51

标签: visual-studio visual-studio-2008 tfs macros

我正在尝试编写一个宏,该宏将生成基于Pending Changes窗格中的文件列表更改的文本的纯文本列表,但我无法弄清楚如何执行此操作。文件的服务器位置是格式如下的属性:

$/TfsName/SomeSolution/Web/SomeFolder/SomeFile1.aspx
$/TfsName/SomeSolution/Web/SomeFolder/SomeFile2.aspx

我能得到的最接近的是打开窗格中所选项目的属性,这不是很有用:

DTE.ExecuteCommand ("TeamFoundationContextMenus.SourceControlPendingChangesSourceFiles.TfsContextPendingCheckinsPendingCheckinsProperties")

编辑:这是我到目前为止的宏的完整代码,TODO是我需要帮助的地方:

Public Class Pending

    Public Shared Sub Pending()
        OutputClear()
        OutputWriteLine("Files Changed:")

        Dim outInfo As String = ""
        DTE.Windows.Item("{2456BD12-ECF7-4988-A4A6-67D49173F564}").Activate() 'Pending Changes - Source Files

        'TODO: loop through each changed file
        'TODO: get TFS server location of each file
        outInfo &= "some file name"

        OutputWriteLine(outInfo)
    End Sub

    ' snip: other supporting functions

End Class

1 个答案:

答案 0 :(得分:2)

好吧我还没弄清楚如何使用宏来做,但是感谢Bob Hardister on twitter,我可以使用这个命令来获取我正在寻找的东西:

"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\tf.exe" status $/ProjectName/SubDir/ /recursive

...但更好的是使用此代码的命令行应用程序:

const string TFSSERVER = "http://TfsServer:8080";
static void Main(string[] args)
{
    //http://blogs.msdn.com/b/buckh/archive/2006/03/15/552288.aspx
    //http://blogs.msdn.com/b/jmanning/archive/2005/12/01/499033.aspx
    string projectName = args[0];
    TeamFoundationServer tfs = new TeamFoundationServer(TFSSERVER);
    VersionControlServer versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
    PendingSet[] sets = versionControl.GetPendingSets(new String[] { "$/Projects/" + projectName }, RecursionType.Full);
    Console.WriteLine(versionControl.AuthenticatedUser + " pending changes for " + projectName + ":");

    foreach (PendingSet set in sets)
    {
        if (set.Type == PendingSetType.Workspace && set.OwnerName == versionControl.AuthenticatedUser)
        {
            foreach (PendingChange pc in set.PendingChanges)
            {
                Console.WriteLine(pc.ServerItem);
            }
        }
    }
}

然后我将已编译的EXE调用添加到“外部工具”菜单中,并在VS中使用它。

奖金编辑:这是VSS版本(不太好):

const string SSDIR = @"\\VssServer\VssShare";
static void Main(string[] args)
{
    string projectName = args[0];
    string userName = "user";

    VSSDatabaseClass vss = new VSSDatabaseClass();
    vss.Open(SSDIR + @"\srcsafe.ini", userName, userName);
    VSSItem sourceItem = vss.get_VSSItem("$/Projects/" + projectName, false);

    Console.WriteLine(userName + " pending checkins for " + projectName + ":");
    int total = GetItems(sourceItem);
    Console.WriteLine(total.ToString() + " total changes.");

}

const int VSSFILE_CHECKEDOUT_ME = 2;
const int VSSITEM_PROJECT = 0;
const int VSSITEM_FILE = 1;
public static int GetItems(IVSSItem originalItem)
{
    int total = 0;
    foreach (IVSSItem subItem in originalItem.get_Items(false))
    {
        if (subItem.Type == VSSITEM_FILE && subItem.IsCheckedOut == VSSFILE_CHECKEDOUT_ME)
        {
            Console.WriteLine(subItem.Spec);
            total++;
        }
        else if (subItem.Type == VSSITEM_PROJECT)
        {
            total += GetItems(subItem);
        }
    }
    return total;
}