Centralize connection strings for multiple projects within the same solution

后端 未结 3 1702
南笙
南笙 2020-12-08 22:13

I currently have three projects in my solution that all have their own App.config file with the same exact connection string.

Is there a way to consolidate the conne

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 22:47

    You can share the connection strings among multiple projects in a solution as follows:

    1. Create a ConnectionStrings.config file with your connection strings under a solution folder, this file should contain only the section connectionStrings

    2. In your projects, add this config file As a Link (add existing item, add as link)

    3. Select the added file and set its property Copy to Output Directory to Copy always or Copy if newer
    4. In the App.config of your projects, point to the linked ConnectionStrings.config file using the configSource attribute:

    ConnectionStrings.config

    
        
    
    

    App.config

    
    
        ...
        
        ...
    
    

    Read more details....

提交回复
热议问题