如何在Visual Studio中以单个操作打开多个文件

问题描述

| 我经常在Visual Studio中使用“命令窗口”来按名称快速打开文件,例如通过键入
open main.c
。 但是,似乎无法使用
open *.xyz
,其目的是打开解决方案中带有扩展名
xyz
的任何文件。 从“命令窗口”有没有一种快速简便的方法可以基于某个模式一次打开多个文件?     

解决方法

我无法使命令窗口正常工作。使用文本编辑器或脚本创建文件列表,如下所示:
\"full path 1\" \"full path 2\"
Ctrl + o并将字符串粘贴到打开的文件对话框中。     ,这是使用Visual Commander(VS附加组件)的解决方案。它使用剪贴板中的文件路径。我倾向于使用
dir /s/b *.??
或使用powershell来生成这些文件路径的另一个更复杂的解决方案,进入命令行。
using EnvDTE;
using EnvDTE80;
using System;
using System.Windows.Forms;
using System.IO;

public class C : VisualCommanderExt.ICommand
{
    public void Run(EnvDTE80.DTE2 DTE,Microsoft.VisualStudio.Shell.Package package) 
    {
        if(Clipboard.ContainsText(TextDataFormat.Text))
        {
            string[] files = Clipboard.GetText(TextDataFormat.Text).Replace(\"\\r\",\"\").Split(new string[] {\"\\n\"},StringSplitOptions.RemoveEmptyEntries);
            foreach(string f in files)
            {
                try 
                {
                    FileInfo fileInfo = new FileInfo(f);
                    if(fileInfo.Exists)
                    {
                        DTE.ItemOperations.OpenFile(f,EnvDTE.Constants.vsViewKindPrimary);
                    }
                }
                catch{ }
            }
        }
    }
}