Office 加载项项目、dll 和 app.config 文件问题
我创建了一个库项目,到目前为止已在大约三个项目中使用。一个 WPF 项目、一个 Windows 窗体项目和一个 Web 应用程序项目。该 dll 使用 App.Config 文件来存储办公室常见的各种密钥,例如网络存储驱动器的路径。所以现在我被要求分别为 MS Office 2010 Excel 和 Access 创建一个插件。
现在,我之前遇到过这样的情况:库项目将使用其调用项目的配置文件,因此我必须将密钥添加到该项目的配置文件中,所以我想我会对这个项目做同样的事情。我开始摆弄它,看看如何让 Office 应用程序调用 dll 方法,并立即发现它没有从 App.Config 文件中找到任何内容。
环顾四周后,我发现 Office 加载项项目实际上只是一个实现 IDTExtensibility2 接口并将自身注册为 COM dll 的项目。所以现在我遇到的情况是,我有一个带有依赖 dll 的 dll,但它们都无法在配置文件中找到任何内容。那么在这种情况下我应该把配置文件放在哪里呢?我尝试将其与 Excel.exe 一起放入 Office 14 文件夹中,以及将其放入与使用该加载项的 Excel 工作表相同的文件夹中,但无济于事。任何想法都将不胜感激。谢谢!
I have a library project that I created and have used in about three projects so far. A WPF project, a Windows Forms project and a web app project. The dll uses an App.Config file for various keys common to the office such as the path to the networked storage drive. So now I have been asked to create a plug in for MS Office 2010 Excel and Access respectively.
Now I have previously run into the situation where the library project will use the config file for its calling project so I had to add the keys into that project's config file so I figured I would be doing the same thing with this project. I come to start fiddling around with it to see how I can get Office apps to call the dll methods and immediately see that it is not finding anything from the App.Config files.
After looking around I see that an Office Add-in project is really just a project implementing the IDTExtensibility2 interface and registering itself as a COM dll. So now I have a situation where I have a dll with a dependent dll and neither of them can find anything in a config file. So where would I put the config file in this case? I have tried putting it in the Office 14 folder with Excel.exe as well as putting it in the same folder as the Excel Worksheet that makes use of the Add-in but to no avail. Any ideas are greatly appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,只是回答这个问题,因为我最终通过反复试验找到了它。如果您尝试将配置文件用于引用 dll 项目的 Office 加载项项目,则使用的配置文件仍将是调用 exe 的配置文件。也就是说,加载项项目调用的 dll 项目将查找分别存储在 MSACCESS.EXE.config 和 EXCEL.EXE.config 中的密钥。使用的配置文件只会沿着 dll 链向上查找,直到找到实际调用的 exe 配置文件。
OK so just to answer this question as I did eventually find it through trial and error. In the case that you are trying to use a config file for an office add-in project that is referencing a dll project, the config file used will still be that of the calling exe. That is to say, the dll project that is called by the add-in project will be looking for keys stored in MSACCESS.EXE.config and EXCEL.EXE.config respectively. The config file used just keeps going up the chain of dlls until it finds the actual calling exe config file.