2016-11-27 138 views
0

我正在開發Visual Studio擴展包。 我需要能夠檢索參考文件的引用路徑(引用文件已被刪除)在Visual Studio Addin中獲取斷開引用的路徑

我無法找到一種方法來執行EnvDTE項目。 當我得到EnvDTE參考

Reference.Path 

損壞的引用路徑將是:「」(如可能預期的一樣,你可以在中VS UI通過參考屬性視圖,路徑將是「」爲好)

我需要一種方式來獲取Dll路徑,因爲它保存在.csproj文件中, 有沒有辦法在Visual Studio擴展中執行?

(我知道如何與Microsoft.Build做到這一點(加載項目,並獲得引用DLL)的,但它看起來怪我使用這種方法,當我在VS插件我工作)

回答

0

您也可以使用Xdocment來實現它。像這樣:

string xmlPath = @"D:\Project\VSX\ConsoleApp\GetReferecePath\GetReferecePath.csproj"; 

      XNamespace msbuild = "http://schemas.microsoft.com/developer/msbuild/2003"; 
      XDocument projDefinition = XDocument.Load(xmlPath); 
      IEnumerable<string> references = projDefinition 
       .Element(msbuild + "Project") 
       .Elements(msbuild + "ItemGroup") 
       .Elements(msbuild + "Reference") 
       .Select(refElem => refElem.Value); 
      foreach (string reference in references) 
      { 
       Console.WriteLine(reference); 
      } 
1

我只是使用Microsoft.Build。 C#項目被加載到全局集合中。

相關問題