2011-05-04 54 views
1

我开发一个Excel VSTO文档级外接使用复合应用程序指南(棱镜为Visual Studio 2008/.NET 3.5)。可扩展的Excel VSTO加载使用棱镜/ CAG /统一调试

其中一个要求是,此加载应该是可扩展的,也就是在运行时它应该允许加载插件的DLL。我创建统一的目录模块目录是这样的:

// the path where the WorkbookProject.dll Add-In (WorkbookProject\bin\Debug) resides 
string fullPath = AppDomain.CurrentDomain.BaseDirectory; 
string theDirectory = Path.GetDirectoryName(fullPath); 

return new DirectoryModuleCatalog() { ModulePath = fullPath }; 

我的简化项目的层次结构是这样的:

Common 
-ref: none 

WorkbookProject // the main project with xlsx workbook (shouldn't reference any PlugIns) 
-ref: Common 

PluginOne 
-ref: Common 
-PostBuildEvent copies output dll to WorkbookProject\bin\Debug 

Setup (temporarily knows all plugins, but they should be installed separately) 
-ref: Common 
-ref: PluginOne 
-ref: WorkbookProject 

这一部署后工作正常(所有DLL驻留在应用程序文件夹由安装程序创建项目),但在调试期间我得到Microsoft.Practices.Composite.Modularity.ModuleCatalog.Load()异常:

System.IO.FileLoadException: API restriction: The assembly 'file:///(...)\WorkbookProject\bin\Debug\Common.dll' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.

在Visual Studio输出/调试窗口,我可以看到,该文件已经从

C:\Users\Me\AppData\Local\assembly\dl3\JWCWD78V.HAZ\H2VHNAYM.XW1\18912686\7e8ea552_620acc01\Common.dll

加载为什么(从WorkbookProject参考)我所有的应用程序文件的调试过程中被复制到AppData目录?可以避免这种情况吗?

难道有所作为,如果我转换从我的工作簿添加项目,在对应用程序插件?

回答

0

嗯,我想我设法解决了这个问题。

似乎在Common.dll上有版本不匹配。

我注意到,在我的调试配置的PluginOne没有检查编译,所以调试过程中的旧版本PluginOne的加载。

我纠正此问题并重新添加对Common.dll的所有引用后,问题不会出现。

现在我的PluginOne.dll从AppData加载(请注意,它发生在运行时,因为DirectoryModuleCatalog路径是WorkBookProject \ bin \ Debug,并且我没有任何对我的.VSTO中的PluginOne的引用或WorkbookProject.dll.manifest)

另请注意,当您使用VS2008的复合应用程序指南时,DirectoryModuleCatalog的指定文件夹不能包含本机dll,否则会引发BadImageFormatException。使用子目录:ModulePath=fullPath+"\Modules"或见GetNotAllreadyLoadedModuleInfos()方法in V4 version of Prism 速战速决)

0

这是一个非常有趣的使用VSTO,你似乎已经整理你的问题,但我只是想知道,如果你会过得更好用更新的技术堆栈来实现这一点。

在Prism上使用MEF的插件架构可能会更清洁,因为每个项目的原因都有很大的不同,而MEF有更清晰的模型,我认为它也可以充当基本的IoC容器。象Autofac这样的容器也给你提供了比统一更明确的生命周期管理,这对于使用COM Interop来说可能是一个优势。
我也有一个项目vsto contrib(http://vstocontrib.codeplex.com/),它也可以帮助你,特别是如果你有通过加载项注册的Ribbon和其他东西。

只是我的2C方法,但总的来说,非常酷,你正在做这一切与VSTO。