How to vary connection string for different work locations

后端 未结 7 2029
情话喂你
情话喂你 2021-02-10 15:55

I am working on a C# 4.0, WPF 4.0, SQL 2008 project and I do work at home and in the office. I just setup SubVersion using Visual SVN per the recommendations found in other ques

7条回答
  •  不知归路
    2021-02-10 16:14

    If you really want to automate this fully, you could do something like this:

    First, store the settings for the different environments in source control, but not the actual configuration file. For example:

    configfiles\app.config.mikeb_home
    configfiles\app.config.local
    configfiles\app.config.development
    configfiles\app.config.staging
    configfiles\app.config.production
    

    Then in your build configuration, you can add a step to copy the right config file to your root app.config. E.g. with a 'pre-build event' (command line script) based on 'environment' parameters (computername, username, ...). You can probably achieve the same thing by adding some msbuild commands in the .csproj file.

    However, is all this really worth it? TortoiseSVN has a feature called the 'ignore-on-commit' list, which helps you prevent accidently committing a locally changed file that shouldn't be committed (in the commit dialog, right-click on the file => Move to Change List -> ignore-on-commit). May be slightly annoying if you actually need to change something else in the .config file, but still.

提交回复
热议问题