0

I'm working on a visual studio extension package. I need to be able to retrieve the reference path of a broken reference (a reference that the Referenced File Has Been removed)

I couldn't find a way to do so with EnvDTE project. when I get the reference with EnvDTE

Reference.Path

the broken reference Path will be: "" (as maybe expected like you can view in the in VS UI via reference Properties, the Path will be "" as well)

I need a way to get the Dll path as it is saved in the .csproj file, Is there a way to do it within visual studio extension??

(I know how to do this with Microsoft.Build (to load the Project and get the referenced Dlls), but it looks weird to me to use this method when I'm working in VS addin)

Efrat
  • 57
  • 8

2 Answers2

1

I'd just use Microsoft.Build. The c# projects are loaded into the global collection.

jmoffatt
  • 99
  • 1
  • 3
0

You can also use Xdocment to achieve it. like this:

  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);
            }
Zhanglong Wu - MSFT
  • 1,652
  • 1
  • 7
  • 8