visual-studio-2012 - VSIX 扩展使用第 3 方 DLL 无法加载依赖项之一

标签 visual-studio-2012 dll visual-studio-extensions vsx vsix

我正在开发 VS2013 的扩展。由于它将通过 MSI 安装,因此我使用包类的 ProvideBindingPath 属性将基本目录更改为安装文件夹。但是将在运行时加载的第 3 方 dll 引用不会从探测路径中选取 dll。它总是查看 Visual studio devenv.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) 程序集。

在 Package 类构造函数中注册 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;
}

我对上述方法没有任何问题。

关于visual-studio-2012 - VSIX 扩展使用第 3 方 DLL 无法加载依赖项之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20001191/

相关文章:

visual-studio - Visual Studio 2012 CPU 使用率高且无法调试

c# - ASP.NET C# 更新查询不工作

c# - 二维标签不起作用

nuget - NuGet 和 NuGet 包管理器有什么区别?

visual-studio-2012 - 安装包: Could not install package WPtoolkit error [duplicate]

c++ - 重定向 MFC GUI 应用程序中使用的 c++ dll 的控制台输出

c++ - Irrlicht 错误 "No Entry point"

c++ - 如何编译 C++ dll 以使用 Lua? (我收到错误加载模块)

visual-studio-2012 - 在 Visual Studio 2012 中以编程方式指定专用扩展库

visual-studio - 在不使用 devenv/setup 的情况下通过 MSI 注册解压的 VSIX 扩展