Hello! How can I get a list of sources of NuGet packages using IVsPackageSourceProvider ? I try to use this design:

  using (Microsoft.VisualStudio.Shell.ServiceProvider provider = new Microsoft.VisualStudio.Shell.ServiceProvider((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)base._dteObject)) { IComponentModel service = (IComponentModel)provider.GetService(typeof(SComponentModel)); try { var sourceProvider = service.GetService<IVsPackageSourceProvider>(); } catch(Exception ex) { } } 

But in the try block, Exception drops with the text:

Can not cast the exported value of type NuGet.VisualStudio.VsPackageSourceProvider (ContractName = "NuGet.VisualStudio.IVsPackageSourceProvider") 'to type' NuGet.VisualStudio.IVsPackageSourceProvider '

Tell me how to properly use this provider.

Thank you in advance!

    1 answer 1

    The cause of the problem, as I understand it, lies in Visual Studio 2012/2013 and NuGet Manager 2.12.0.817 .

    Moreover, the project is successfully assembled with such strings, however, during execution on the specified products it drops successfully.

    Works correctly on Visual Studio 2015 and NuGet Manager 3.4.4.1321 .