Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a config type file for Visual Studio Add-In?

When creating a Visual Studio Add-In, how can you utilise an app.config for the add-in. If I add one to the project and deploy it then when the Add-In runs and I programmatically try to access it via the ConfigurationManager.AppSettings its not picking up the config file for the add-in.
Am I doing something wrong or is there another means to access file based configuration settings for an add-in?

like image 224
gouldos Avatar asked Oct 13 '10 15:10

gouldos


People also ask

Where is Visual Studio config file?

Settings. settings is located in the My Project folder for Visual Basic projects and in the Properties folder for Visual C# projects. The Project Designer then searches for other settings files in the project's root folder.

Where can I find config file?

Configuration files are normally saved in the Settings folder inside the My Documents\Source Insight folder.

What is the file extension for config?

A CONF file is a configuration or "config" file used on Unix and Linux based systems. It stores settings used to configure system processes and applications. CONF files are similar to . CFG files found on Windows and Macintosh systems.


1 Answers

ConfigurationManager.AppSettings picks up the configuration file for the AppDomain you are loaded into. That config file is typically the one associated with the entry point executable. In your case, you don't control the entry point executable nor the AppDomain you run in so you can't use ConfigurationManager.AppSettings.

You question basically boils down to "How can I have a config file associated with a DLL?" (C# Dll config file). You need to do two things:

  1. Add an Application Configuration File item to your project and make sure you deploy it to the same folder as your DLL.
  2. Access the config file from your DLL using code like this:

     string pluginAssemblyPath = Assembly.GetExecutingAssembly().Location;
     Configuration configuration = ConfigurationManager.OpenExeConfiguration(pluginAssemblyPath);
     string someValue = configuration.AppSettings.Settings["SomeKey"].Value;
    

That will definitely work for regular DLLs that are not loaded using shadow copy. I'm not sure how VS loads its plugins. If you run into problems, let me know and I can post a work around for DLLs that get loaded via shadow copy.

like image 81
Russell McClure Avatar answered Sep 19 '22 17:09

Russell McClure