如果 DLL 的 app.config 应该在“主配置"中……我们如何处理 DLL 中的 WCF 引用? [英] If app.config for a DLL should be in the "main config"… what do we do with WCF References in DLLs?

查看:22
本文介绍了如果 DLL 的 app.config 应该在“主配置"中……我们如何处理 DLL 中的 WCF 引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这很简单,但据我所知……您只能使用某种 Windows 工作流将另一个配置包含到另一个配置中(我拒绝这样做).

Ok, this is rather simple, but from what I've seen… you can only use some sort of Windows Workflow to include another config into another (which I refuse to do).

交易如下:

MAINAPP.EXE 引用了一个假设的 LIBRARY.DLL.

MAINAPP.EXE References an hypothetical LIBRARY.DLL.

MAINAPP.EXE 有自己的 MAINAPP.EXE.config.

MAINAPP.EXE has its own MAINAPP.EXE.config.

如果您将配置值"添加到 LIBRARY.DLL(从而在 LIBRARY.DLL 项目中创建 app.config),这些值在运行时 可用 即使您复制应用程序.config 到 LIBRARY.DLL.config 到构建后的正确路径.

If you add "config values" to LIBRARY.DLL (thereby creating an app.config in LIBRARY.DLL project), those values are not available at runtime even if you copy app.config into LIBRARY.DLL.config to the right path post-build.

上述原因是即使引用的库也会从mainapp.exe"配置中读取.

The reason for the above is that even referenced libraries will read from the "mainapp.exe" config.

到目前为止很好".现在,当您添加 WCF 服务引用时,visual studio 会使用绑定/端点/等创建或填充您的 app.config;但这已添加到您添加引用配置的项目中;因此,您的 Library.DLL.prj 最终会得到一个很好的 app.config,它不起作用,因为它永远不会被读取,甚至不会被复制到输出目录.现在您可能认为您可以右键单击该 app.config 并将始终复制"设置为 true.算了吧.那没有任何作用.(你可以用谷歌搜索那个).

So far "so good". Now, when you add a WCF Service reference, visual studio creates or populates your app.config with the bindings/endpoints/etc.; but that's added to the project where you added the reference's config; hence, your Library.DLL.prj ends up with a nice app.config that doesn't work because it never gets read, nor even copied to the output directory. Now you may think that you can right click that app.config and set "copy always" to true. Forget it. That doesn't do anything. (You can google for that one).

那么,鉴于上述奇怪的场景,使用 .NET 3.5 项目的常规 VS2008 开发人员如何管理他添加到业务层 dll 中的 WCF 服务引用?该开发人员是否应该在每次服务发生更改或每次更改时将其 DLL 中 无用 app.config 中的所有部分复制并粘贴到 Mainapp.exe.config 文件中?他添加/删除一个?

So, given the above weird scenario, how is a regular VS2008 developer working with a .NET 3.5 project going to manage the WCF service references he adds to his Business Layer dll? Is that developer supposed to COPY and PASTE all the whole section from the useless app.config in his DLL to the Mainapp.exe.config file each time there's a change in the services or each time he adds/removes one ?

推荐答案

是的.复制和粘贴就是答案.这不是一个很好的答案,但它就是答案,而且从 .NET 1.0 的第 1 天开始,它就带有 AppSettings.

Yes. Copy and paste is the answer. It's not a great answer, but it's the answer, and it has been since day 1 in .NET 1.0 with AppSettings.

这篇关于如果 DLL 的 app.config 应该在“主配置"中……我们如何处理 DLL 中的 WCF 引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆