Best Approach For Configuring Multiple .Net Applications

前端 未结 5 1106
死守一世寂寞
死守一世寂寞 2020-12-11 07:10

We have a suite of interlinked .Net 3.5 applications. Some are web sites, some are web services, and some are windows applications. Each app currently has its own configurat

相关标签:
5条回答
  • 2020-12-11 07:50

    These 2 questions might help you: Utilizing machine.config and Managing app.config for large projects

    0 讨论(0)
  • 2020-12-11 07:56

    Check out the prism framework from Microsofts patterns and practices group?

    0 讨论(0)
  • 2020-12-11 07:59

    Visual Studio has a relatively obscure feature that lets you add existing items as links, which should accomplish what you're looking for. Check out Derik Whittaker's post on this topic for more detail.

    Visual Studio really should make this option more visible. Nobody really thinks to click on that little arrow next to the "Add" button.

    0 讨论(0)
  • 2020-12-11 08:09

    We use file templates such as MyApp.config.template and MyWeb.config.template with NAnt properties for the bits that are different between environments. So the template file might look a bit like this:

    <MyAppConfig>
        <DbConnString>${DbConnString}</DbConnString>
        <WebServiceUri uri="${WebServiceUri}" />
    </MyAppConfig>
    

    During a build we generate all the configs for the different environments by just looping through each environment in a NAnt script, changing the value of the NAnt properties ${DbConnString} and ${WebServiceUri} for each environment (in fact these are all set in a single file with sections for each environment), and doing a NAnt copy with the option to expand properties turned on.

    It took a little while to get set up but it has paid us back at least tenfold in the amount of time saved messing around with different versions of config files.

    0 讨论(0)
  • 2020-12-11 08:15

    You can split App.config into multiple configuration files. You just specify the name of the file that contains the config section.

    Change app.config:

    <SomeConfigSection>
      <SettingA/>
      <SettingB/>
    </SomeConfigSection>
    <OtherSection>
      <SettingX/>
    </OtherSection>
    

    Into app.config and SomeSetting.xml:

    <SomeConfigSection file="SomeSetting.xml" />
    <OtherSection file="Other.xml" />
    

    Where SomeSetting.xml contains:

    Now you can compose your app.config from different section files with some sort of build or deploy script. E.g.:

    if debug copy SomeSettingDebug.xml deploydir/SomeSetting.xml
    if MySql copy OtherSectionMySql.xml deploydir/OtherSetting.xml
    
    0 讨论(0)
提交回复
热议问题