简体   繁体   中英

How do I change the default application config/setting in different deployments?

I have ac# class library that builds into a DLL.

I have some setting values, like paths to directories, that I use inside the class library.

I would like to make it so, that whomever references the DLL has a chance to edit the default values of the settings (preferably through a file). Like,

[In the class library] Default value would be FooDir = "C:/Program files/"

[Project X references the library] We would like to change the FooDir's value to "C:/Program files(x86)/".

It would be neat, if Visual Studio would generate a XML file containing the FooDir config/setting and then copy it to Project X's output directory. And then we could change the FooDir's value there and this new value of FooDir would be reflected when running Project X.

How can I achieve this?

Your best bet here is to create a Custom COnfiguration section for your application, set defaults for everything, then if the users want to override anything they can add the configuration section to their app.config or web.config file.

It is very easy, and quick to do. Here is a step-by-step tutorial .

This follows standards that have been established with .NET and should be very familiar for any users.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM