我正在開發的擴展,VS2013之一。因爲它會通過MSI安裝,我使用ProvideBindingPath屬性打包類變更基本目錄來安裝文件夾。但是在運行時加載的第三方dll引用並不是從探測路徑中選取dll。它總是看着Visual Studio devenv.exe文件夾。有沒有辦法強制DLL查看我的安裝文件夾。VSIX擴展使用第三方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;
}
}
是否已經'ProvideBindingPath'屬性被移動到另一個的名稱空間;在VS2012中,此類型位於'Microsoft.VisualStudio.Shell'之前。我會嘗試不初始化'SubPath'屬性。並且:彙編元數據是隻讀的;我會說設置反射屬性上的SubPath屬性沒有任何影響... – Matze
Matze,ProvideBindingPath屬性沒有移動到任何其他名稱空間,它來自建模類。 [鏈接](http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.modeling.shell.providebindingpathattribute(v=vs.120).aspx)這是工作的罰款與VS2010。問題在我將代碼遷移到2013年時開始。同一段代碼無法運行。 –
我解決了使用LoadLibrary()從System.Runtime.InteropServices問題; 因爲我要加載的DLL是COM iterop。 public static class win32 { [DllImport(「kernel32.dll」)] public static extern IntPtr LoadLibrary(string dllToLoad); [的DllImport( 「KERNEL32.DLL」)] 公共靜態外部的IntPtr GetProcAddress的(IntPtr的HMODULE,串過程名); [的DllImport( 「KERNEL32.DLL」)] 公共靜態的extern BOOL FreeLibrary則(IntPtr的HMODULE); } in package.cs我寫了這個 win32.LoadLibrary(Path.Combine(installationPath,「apidsp_windows.dll」)); –