Visual Studio 2013/TFS:以一种风格工作,以另一种风格提交



我想知道是否有办法做到这一点,当我签出一个文件时,它会格式化为我的 Visual Studio 样式,但它在签入之前格式化回自定义样式(请注意,任何一种样式都可以在 Visual Studio 中配置,但我一次只知道如何配置一种(。 我想自动化这一点,但即使能够让Visual Studio记住我可以手动切换的两种不同样式也会有所帮助(例如,CTRL-K CTRL-D 用于样式 1,CTRL-K CTRL-E 用于样式 2(。

到目前为止,研究只发现了 TFS 的服务器端事件处理程序,但我想要一个"在我的桌面上"的解决方案。

最坏的情况是,我会尝试编写自己的 VS 扩展,但这是"我不能成为第一个想要这样做的人"的时刻之一。

所以我已经制定了一个部分解决方案。 这并不好或漂亮,但对于任何有类似愿望的人来说,这都是一个不错的起点。 我希望将来能改进它。

首先,以正常方式在Visual Studio中设置样式1,以便CTRL-K,CTRL-D将其格式化为样式1。

其次,下载并安装软件以制作Visual Studio扩展。 这是它的基本指南。

第三,为菜单命令创建一个开箱即用的标准 VSPackage。 以下是基础知识。

第四,在

创建的代码中,在 MenuItemCallback 中添加以下内容。 这会设置一个自定义函数(示例中的 editFiles(以在签入时运行。 请注意,这要求您在单击菜单项时查看团队资源管理器的"挂起的更改"页(我计划在不必这样做的情况下完成这项工作(。

ITeamExplorer teamExplorer = (ITeamExplorer)this.GetService(typeof(ITeamExplorer));
if(teamExplorer != null)
{
    if(teamExplorer.CurrentPage != null && teamExplorer.CurrentPage.GetType().ToString() == "Microsoft.VisualStudio.TeamFoundation.VersionControl.PendingChanges.PendingChangesPageVS")
    {
        if (teamExplorer.CurrentPage.PageContent != null)
        {
            Type pendingChangesPageViewType = teamExplorer.CurrentPage.PageContent.GetType();
            FieldInfo field = pendingChangesPageViewType.GetField("checkinButton", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance);
            System.Windows.Controls.Button checkinButton = (System.Windows.Controls.Button)field.GetValue(teamExplorer.CurrentPage.PageContent);
            checkinButton.Click += new System.Windows.RoutedEventHandler(editFiles);
        }
    }
    else
    {
        IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
        Guid clsid = Guid.Empty;
        int result;
        Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
                0,
                ref clsid,
                "VSPTest01",
                string.Format(CultureInfo.CurrentCulture, "This function only works on the Pending Changes page of Team Explorer."),
                string.Empty,
                0,
                OLEMSGBUTTON.OLEMSGBUTTON_OK,
                OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                OLEMSGICON.OLEMSGICON_INFO,
                0,        // false
                out result));
    }
}

第五,在 MenuItemCallback 所在的同一类中,添加在单击按钮时调用的函数。

public void editFiles(object sender, RoutedEventArgs e)
{
    EnvDTE.IVsExtensibility extensibility = GetService(typeof(EnvDTE.IVsExtensibility)) as EnvDTE.IVsExtensibility;
    EnvDTE80.DTE2 dte = extensibility.GetGlobalsObject(null).DTE as EnvDTE80.DTE2;
    VersionControlExt vce = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as VersionControlExt;
    foreach(var pendingChange in vce.PendingChanges.IncludedChanges)
    {
        string filePath = pendingChange.LocalItem;
        //Do your style changes here, file by file, however you would like.
        //Preferably have some styling software you call.
    }
}

最后,将此VSPackage添加到您的Visual Studio中。

正如我所说,这是一个粗略的解决方案,仍然需要一些工作。 一旦我解决了它,我会改进它。 如果有人知道更好的东西,请务必用它回答这个问题。

相关内容

最新更新