为引用的程序集的Visual C#app.config文件 [英] Visual C# app.config file for a referenced assembly

查看:157
本文介绍了为引用的程序集的Visual C#app.config文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个Visual Studio 2010的解决方案,包含按照杰弗里巴勒莫的洋葱结构模式(http://jeffreypalermo.com/blog/the-onion-architecture-part-1/)几个C#项目。我们有一个用户界面项目,是一个ASP.Net MVC项目,我们有一个由UI项目中引用的C#类库项目名为基础设施。在我们的基建项目,我们已经添加了一个app.config文件包含特定于基础设施项目设置。在运行时,app.config文件不会出现可用的基础设施项目,始载于UI项目的web.config文件。我们不希望把,涉及到基础设施项目到UI项目的web.config文件设置,UI已经不需要这些设置。我们怎样才能使基础设施的app.config文件在运行时可用?我们想也许我们应该把后生成复制到在app.config出复制到当应用程序是建立在UI目录 - 这是正确的方式做到这一点,还是有更好的办法

We have a Visual Studio 2010 solution that contains several C# projects in accordance with Jeffery Palermo's Onion Architecture pattern (http://jeffreypalermo.com/blog/the-onion-architecture-part-1/). We have a UI project that is an ASP.Net MVC project, and we have a C# Class Library project called Infrastructure that is referenced by the UI project. In our Infrastructure project we have added an app.config file to contain settings that are specific to the Infrastructure project. At runtime, the app.config file doesn't appear to be available to the Infrastructure project, only the web.config file contained in the UI project. We don't want to put settings that pertain to the Infrastructure project into the web.config file in the UI project, the UI has no need for those settings. How can we make the Infrastructure's app.config file available at runtime? We were thinking maybe we should put a Post Build Copy to copy the app.config out to the UI directory when the application is built - is that the right way to do this, or is there a better way?

推荐答案

即使你生成后,复制也不会解决你的问题在app.config。该应用程序仍然是一个Web应用程序,所以配置系统将使用web.config文件。这些设置将需要有这样或那样去。仍保持这些有点分开设置的方法之一是把它们放入一个自定义配置部分,然后把设置本节成一个单独的文件。它仍然需要从web.config中引用虽然(使用的 configSource 属性)。

Even if you post-build-copy the app.config it will not solve your problem. The application is still a web app, so the config system will use the web.config file. The settings will need to go in there one way or another. One way to still keep those settings a bit separate is to put them into a custom config section, and then put the settings for this section into a separate file. It will still need to be referenced from the web.config though (using a configSource attribute).

这篇关于为引用的程序集的Visual C#app.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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