Can we have multiple App.Config files in .NET console application?

后端 未结 2 983
离开以前
离开以前 2020-12-19 01:45

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

Now I am thinking to h

相关标签:
2条回答
  • 2020-12-19 02:25

    UPDATE

    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.

    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).

    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.

    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/

    0 讨论(0)
  • 2020-12-19 02:46

    To follow on from Babak's answer, you could also separate parts of your config out into other config files by using the configSource attribute on any element which represents a ConfigurationSection, e.g.:

    <appSettings configSource="appSettings.config" />
    

    And in appSettings.config:

    <?xml version="1.0" encoding="UTF-8"?>
    <appSettings>
        <add key="Blah" value="Nim nim nim" />
    </appSettings>
    
    0 讨论(0)
提交回复
热议问题