我正在开发 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/