app.config - 它应该去哪里?
这是这里的后续内容: 在 app.config 之外存储数据库设置
我知道可以有一个 app.config,其中不同的部分被外部化,并且全部具有不同的值。但是它们是否像 asp.net 项目中的 web.config 文件一样,您只需将其复制到与其余文件相同的文件夹中即可工作,或者我是否需要在某个地方编译它。
另外,它不会被.exe.config文件覆盖吗?
编辑
好的,所以我这个问题的措辞有点糟糕。我已经更新了。
This is a follow on from here: Storing database settings outside app.config
So I know it's possible to have one app.config, with different sections externalised, all with different values. But are they like the web.config files in asp.net projects where you can just copy it into the same folder as the rest of the files and it will work, or do I need to compile it in somewhere.
Also, won't it be overwritten by the .exe.config file?
Edit
Ok, so I worded this question a bit badly. I've updated it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Winforms 或控制台应用程序只有一个配置 - 在您的项目中称为
app.config
,并将通过以下方式重命名为YourApplication.exe.config
构建应用程序时的 Visual Studio。Winform 和控制台应用程序不具有与 Web 应用程序相同的“分层”配置。
您可以将某些配置部分外部化为单独的配置,这些配置将通过 configSource= 属性合并到其中,该属性在每个配置部分都可用,但仅此而已。
如果您的
app.config
引用其他外部配置的某些配置部分,那么您的MyApp.exe.config
将在每次编译时重新创建 - 但其他的外部化的配置将被保留(除非您在构建过程中也专门做了一些事情来覆盖它们)。当然,您也可以通过编程方式加载和解析其他配置文件,但这完全取决于您,而不是基本 .NET 配置系统的一部分。
您还应该查看 CodeProject 上 Jon Rista 关于 .NET 2.0 配置的三部分系列。
强烈推荐,写得很好,非常有帮助!
Winforms or console apps only have one config - it's called
app.config
in your project, and will be renamed toYourApplication.exe.config
by Visual Studio when building the app.Winforms and console apps do not feature the same kind of "hierarchical" configuration like web applications do.
You can externalize certain config sections into separate configs that will be merged in by means of the
configSource=
attribute which is available on every configuration section, but that's about as far as it goes.If you have your
app.config
referencing other external config's for certain config sections, then yourMyApp.exe.config
will be re-created every time you compile - but the other externalized config's will be left alone (unless you specifically do something to overwrite them, too, in your build process).You can of course programmatically also load and parse additional config files, but that's entirely up to you and not part of the basic .NET config system.
You should also check out Jon Rista's three-part series on .NET 2.0 configuration up on CodeProject.
Highly recommended, well written and extremely helpful!