2017-06-22 134 views
0

我用一個自定義菜單創建了一個Visual Studio Package項目,我想添加到Visual Studio(2013)中。如何從Visual Studio Package項目獲取當前的解決方案名稱?

我想在運行時獲取當前的解決方案名稱/目錄。

我試過這個解決方案:

DTE dte = (DTE)GetService(typeof(DTE)); 
string solutionDir = System.IO.Path.GetDirectoryName(dte.Solution.FullName); 

dte.Solution.FullName總是空空的。

雖然它與我在調試模式下運行併爲此創建Visual Studio的新實例有關,但它也發生在我安裝了擴展並從Visual Studio運行它時跑了任何菜單。

任何想法我失蹤了?

謝謝

P.S.我使用的解決方案就是從這裏取:
How do you get the current solution directory from a VSPackage?

回答

0

試試這個:

var solutionName = Path.GetFileName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); 

您需要使用 System.IO System.Diagnostics程序。在解決方案名稱的末尾也可能有一些文件擴展名,您需要修剪。

相關問題