【问题标题】:Get path of project created in experimental Instance of Visual Studio获取在 Visual Studio 实验实例中创建的项目的路径
【发布时间】:2015-03-22 05:11:55
【问题描述】:

我正在开发一个 Visual Studio 扩展包。每次我测试运行时,都会打开一个 VS 的实验实例。我在实验实例中创建了一个项目;如何获取实验实例中创建的项目的路径?

【问题讨论】:

    标签: visual-studio visual-studio-extensions visual-studio-project


    【解决方案1】:

    鉴于代表项目层次结构的IVsHierarchy 对象,您可以在使用VSHPROPID_ProjectDir / VSHPROPID_Name properties 调用GetProperty 方法时使用VSITEMID_ROOT id。

    或者,如果您有EnvDTE.Project,则可以使用EnvDTE.Project.FullName 属性。

    【讨论】:

      【解决方案2】:

      首先应该导入 EnvDTE(在 EnvDTE.dll 中)。然后我声明了属性 ProejectFullName

      string ProejectFullName{ get; }
      

      表示项目对象文件的完整路径和名称的字符串。

      public void GetmyFilePath(DTE2 dte)
      
      {  
          try
          {   // Open a project before running this sample.
              Project prj = dte.Solution.Projects.Item(1);
              Projects prjs;
      
      
      string msg, msg2 = "Global Variables:";
          msg = "FileName: " + prj.FileName;
          msg += "\nProejectFullName: " + prj.ProejectFullName;
          msg += "\nProject-level access to " + prj.CodeModel.CodeElements.Count.ToString() +
              " CodeElements through the CodeModel";
          prjs = prj.Collection;
          msg += "\nThere are " + prjs.Count.ToString() + " projects in the same collection.";
          msg += "\nApplication containing this project: " + prj.DTE.Name;
          if (prj.Saved)
              msg += "\nThis project hasn't been modified since the last save.";
          else
              msg += "\nThis project has been modified since the last save.";
          msg += "\nProperties: ";
          foreach (Property prop in prj.Properties)
          {
              msg += "\n  " + prop.Name;
          }
          foreach (String s in (Array)prj.Globals.VariableNames)
          {
              msg2 += "\n  " + s;
          }
      
          MessageBox.Show(msg, "Project Name: " + prj.Name);
          MessageBox.Show(msg2);
      }
      catch(Exception ex)
      {
          MessageBox.Show(ex.Message);
      }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-07-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多