我们可以在.NET控制台应用程序的多个的App.config文件?多个、我们可以、控制台、应用程序

2023-09-03 00:55:19 作者:早知你是梦

我有一个控制台应用程序有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?

鸭preciate你的帮助。

Appreciate your help.

感谢

推荐答案

更新

是的Visual Studio 2010 和 2012 ,你这已经全部集成到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).

龙的答案,你应该用什么样的企业库MergeConfiguration工具。这样您就可以使用您现有的App.config为基础,确定每个环境的增量。该工具将合并在基座和增量以产生环境specifig配置文件。您仍需要一些逻辑在构建脚本来应用正确的配置文件。

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.

在您的计算机上安装企业库,你可以右键点击该配置文件在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.$c$cplex.com/