How do you get the solution directory in C# (VS 2008) in code?

后端 未结 6 2352
时光取名叫无心
时光取名叫无心 2020-12-10 05:29

Got an annoying problem here. I\'ve got an NHibernate/Forms application I\'m working through SVN. I made some of my own controls, but when I drag and drop those (or view som

6条回答
  •  感情败类
    2020-12-10 06:06

    This is probably coming a little bit late, but I've found a solution at http://www.tek-tips.com/viewthread.cfm?qid=1226891&page=164. Since I am using Visual Studio 2010, I made a few minor changes. You have to reference the EnvDTE and EnvDTE100 (EnvDTE90 for VS2008),

    string solutionDirectory = ((EnvDTE.DTE)System.Runtime
                                                  .InteropServices
                                                  .Marshal
                                                  .GetActiveObject("VisualStudio.DTE.10.0"))
                                       .Solution
                                       .FullName;
    solutionDirectory = System.IO.Path.GetDirectoryName(solutionDirectory);
    

    Of course I used VisualStudio.DTE.10.0, you should probably use VisualStudio.DTE.9.0.

    Good luck!

提交回复
热议问题