Visual studio 2012 VSIX扩展使用第三方DLL无法加载其中一个依赖项

Visual studio 2012 VSIX扩展使用第三方DLL无法加载其中一个依赖项,visual-studio-2012,dll,visual-studio-extensions,vsx,vsix,Visual Studio 2012,Dll,Visual Studio Extensions,Vsx,Vsix,我正在开发VS2013的扩展。由于它将通过MSI安装,因此我将使用包类的ProvideBindingPath属性将基本目录更改为安装文件夹。但将在运行时加载的第三方dll引用没有从探测路径中拾取dll。它总是查看VisualStudiodevenv.exe文件夹。有没有办法强制dll查看我的安装文件夹 using MD=Microsoft.VisualStudio.Modeling.Shell; MD.ProvideBindingPath(SubPath = @"")] public seal

我正在开发VS2013的扩展。由于它将通过MSI安装,因此我将使用包类的ProvideBindingPath属性将基本目录更改为安装文件夹。但将在运行时加载的第三方dll引用没有从探测路径中拾取dll。它总是查看VisualStudiodevenv.exe文件夹。有没有办法强制dll查看我的安装文件夹

using MD=Microsoft.VisualStudio.Modeling.Shell;

MD.ProvideBindingPath(SubPath = @"")]
public sealed class AutomationCommandPanePackage : Package
    { 

     public AutomationCommandPanePackage()        
     {

        string installationPath = HelperMethods.GetInstallationPath();

        if (string.IsNullOrEmpty(HelperMethods.GetInstallationPath())) return;

        // Change default config file at runtime.
        using (AutomationConfigurationManager.Change(installationPath, "AutomationPro.config"))
        {
            // Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering constructor for: {0}", this.ToString()));
        }            

        Assembly a = Assembly.GetExecutingAssembly();
        Type type = a.GetType("AutomationCommandPanePackage", true);
        System.Reflection.MemberInfo info = type;
        var attributes = info.GetCustomAttributes(true);

        foreach (var attrib in attributes)
        {
            if (attrib is MD.ProvideBindingPathAttribute)
            {
                ((MD.ProvideBindingPathAttribute)attrib).SubPath = installationPath;
                break;
            }
        }            

我已经能够使用下面的代码成功地在我的扩展中加载第三方(telerik)程序集

在包类构造函数中注册到
AssemblyResolve
事件

AppDomain.CurrentDomain.AssemblyResolve += OnAssemblyResolve;
然后在处理程序中加载包,如下所示:

string path = Assembly.GetExecutingAssembly().Location;
path = Path.GetDirectoryName(path);

if (args.Name.ToLower().Contains("telerik.windows.controls.gridview"))
{
       path = Path.Combine(path, "telerik.windows.controls.gridview.dll");
       Assembly ret = Assembly.LoadFrom(path);
       return ret;
}
我对上述方法没有任何问题。

我使用
LoadLibrary()
from

System.Runtime.InteropServices; 
因为要加载的dll是COM iterop dll

public static class win32 
{ 
[DllImport("kernel32.dll")] 
public static extern IntPtr LoadLibrary(string dllToLoad); 
[DllImport("kernel32.dll")] 
public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); [DllImport("kernel32.dll")] 
public static extern bool FreeLibrary(IntPtr hModule);
}
在package.cs中,我像这样加载了程序集

win32.LoadLibrary(Path.Combine(installationPath, "apidsp_windows.dll")); 

ProvideBindingPath
属性是否已移动到另一个命名空间;在VS2012及之前,此类型位于Microsoft.VisualStudio.Shell中。我将尝试不初始化
子路径
属性。和:程序集元数据是只读的;我想说的是,在反射属性上设置
SubPath
属性没有任何效果…Matze,ProvideBindingPath属性没有移动到任何其他名称空间,它来自建模类。[link]()VS2010运行良好。问题始于我将代码迁移到2013年。同一段代码不起作用;因为我要加载的dll是COM iterop。公共静态类win32{[DllImport(“kernel32.dll”)]公共静态外部IntPtr加载库(字符串dllToLoad);[DllImport(“kernel32.dll”)]公共静态外部IntPtr GetProcAddress(IntPtr hModule,字符串procedureName);[DllImport(“kernel32.dll”)]公共静态外部bool freellibrary(IntPtr hModule);}在package.cs中,我编写了这个win32.LoadLibrary(Path.Combine(installationPath,“apidsp_windows.dll”));有两个属性类具有相同的名称,但预期用途不同。解决此问题的属性类在
Microsoft.VisualStudio.Shell
命名空间中声明。请参阅:谢谢,Utkarsh,在我的情况下,DLL在执行路径中不可用。MSI将把它们放在安装文件夹中。您将它们放在哪里上面的代码(
[DLLImport(…
)?