我们可以在 .NET 控制台应用程序中有多个 App.Config 文件吗? [英] Can we have multiple App.Config files in .NET console application?

查看:57
本文介绍了我们可以在 .NET 控制台应用程序中有多个 App.Config 文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 App.Confile 文件的控制台应用程序.现在这里保留了特定于环境的参数.

I have a console application that has App.Confile file. Now the parameters that are environment specific are maintained here.

现在我想有多个 app.config 文件(例如 app.dev.config、app.test.config 和 app.prod.config)我们如何拥有多个 Web.Config 文件.

Now I am thinking to have multiple app.config files (like app.dev.config, app.test.config and app.prod.config) the way how we can have multiple Web.Config files.

如果是 Web 应用程序,我们可以处理这个,ConfigurationManager 会选择相应的 Web.Config 文件.

In case of Web application, we can handle this and ConfigurationManager would pick respective Web.Config file.

对于控制台应用程序,我不确定.如果是,我们怎么会有多个 app.config 文件?

In case of Console application, I am not sure. If Yes, how can we have multiple app.config files?

感谢您的帮助.

谢谢

推荐答案

UPDATE

Visual Studio 20102012 中,这些都已集成到 IDE 中.如果右键单击配置文件,VS 会为您提供为每个构建配置生成转换配置的选项.如果您要为每个环境创建构建配置,MSBuild 将自动为您生成正确的 Web.config/app.config.

With Visual Studio 2010 and 2012, you this has all been integrated into the IDE. If you right click your config file, VS give you the option to generate a transform config for each of your build configurations. If you were to create a build configuration for each of your environments, MSBuild will automatically generate the correct Web.config/app.config for you.

简短回答,是的.您可以在构建脚本中使用不同的文件,但您必须将正确的文件重命名为App.config",然后您就可以设置(在编译之前).

Short answer, yes. You can have the different files and in your build script, but you'll have to rename the correct one to "App.config" and you're set (before you compile).

长答案,您应该使用的是 Enterprise Library MergeConfiguration 工具.这允许您使用现有的 App.config 作为基础并定义每个环境的增量.该工具将合并基础和增量以生成特定于环境的配置文件.您仍然需要在构建脚本中使用一些逻辑来应用正确的配置文件.

Long answer, what you should be using is the Enterprise Library MergeConfiguration tool. This allows you to use your existing App.config as the base and define deltas per environment. The tool will merge the base and the delta to generate the environment-specifig config files. You will still need some logic in a build script to apply the correct config file.

当您在您的机器上安装 Enterprise Library 时,您可以在 Visual Studio 中右键单击配置文件并通过配置工具对其进行编辑.您可以使用它来定义您的环境以及要覆盖每个环境的应用设置和连接字符串.

When you install Enterprise Library on your machine, you can right click the config file in Visual Studio and edit it via the config tool. You can use that to define your environments and the app settings and connection strings to override per environment.

http://entlib.codeplex.com/

这篇关于我们可以在 .NET 控制台应用程序中有多个 App.Config 文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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