代码之家  ›  专栏  ›  技术社区  ›  Alex

在Visual Studio(2010)中以编程方式打开文件

  •  7
  • Alex  · 技术社区  · 14 年前

    我正在构建一个VS包,并尝试将该包中的命令发送到Visual Studio,以便在新选项卡中打开用户选择的文件(就像用户通过转到file->打开。

    2 回复  |  直到 10 年前
        1
  •  8
  •   Chris Schmich    14 年前
        2
  •  8
  •   philiphobgen    14 年前

    在本例中,ExecuteCommand(“File.OpenFile”)

    如果需要,可以在第二个可选字符串参数中向命令添加参数。

        3
  •  0
  •   SergeyT    5 年前

    您可以使用此功能: VsShellUtilities.OpenDocument

    如果从VSPackage方法调用它,它看起来像:

    VsShellUtilities.OpenDocument(this, fileName);
    

    命名空间: Microsoft.VisualStudio.Shell

    组件: Microsoft.VisualStudio.Shell.15.0.dll , Microsoft.VisualStudio.Shell.14.0.dll

    它还有两个重载,返回打开文档的附加信息。

    注:此功能在VS 2015及更高版本中可用。