Search code examples
c#.net-2.0

Reuse an existing app config


How I can reuse an app config of an existing application? Given that the app config is located in a common repository of a network accessible for all.

I found this snippet:

System.Configuration.ConfigurationFileMap fileMap = new ConfigurationFileMap(strConfigPath); //Path to your config file
    System.Configuration.Configuration configuration = System.Configuration.ConfigurationManager.OpenMappedMachineConfiguration(fileMap);

But I got this error in my application, I am using .Net 2.0

The type or namespace name 'ConfigurationFileMap' does not exist in the namespace 'System.Configuration' (are you missing an assembly reference?) The type or namespace name 'Configuration' does not exist in the namespace 'System.Configuration' (are you missing an assembly reference?)

How should I do this?


Solution

  • App.config by default is embedded in your assembly. One option i would recommend is to add your shared app.config as a linked item, Project -> Add Existing Item -> \Shared\App.Config -> (Small arrow next to add) -> Add as link

    This basicly makes a shortcut to the actual file