Class Library project no Reference option RRS feed

  • Question

  • Hallo

    Our application consist of three different project, The core is shared classes between the other two projects, but we need to save settings like connectionstring in the core, where the front end will edit these files, and the service will just read the connectionstrings from the file. We created a ConnectionString.config file and want the create a class in the core project that will be able to get and set the connection string with two methods in the same class. (Other projects will be able to call the methods from any project.

    But the issues is I cannot find a way to read or to write to our ConnectionString.config files. also we cannot add a reference to the class library which might be able to get this done throught the ConfigurationManager which is a class in System.Configuration.

    Is there a way to add a reference file to a class library, or what is the best practice to get a file that can be shared by all other programs?


    Wednesday, June 24, 2020 9:17 PM

All replies

  • Here is a set of instructions

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Wednesday, June 24, 2020 11:57 PM
  • I don't particularly agree it is a good idea myself. I think you should abstract your configuration so you aren't reliant on configuration files (or any specific configuration setup). But you can access ConfigurationManager from any code. You will not have any .config files in any projects other than the EXE as they aren't used.

    If you want to use a custom config file then you'll need to step back to the Configuration class instead which is the actual wrapper around a config file. ConfigurationManager is simply a static class that wraps the default Configuration instance for the app. You can use CM to open any config file. The biggest challenge you'll have is getting the correct path. If the "new" config file needs to be where the current app config is then you'll have to find it. I believe you can get it from the CM directly but otherwise it'll be in the app's root directory. Irrelevant, once you've identified the path you can open the file and write to it. 

    Note that apps do not have write access to the app's directory by default. The installer would have to change the folder permissions before you can write to the app's directories.

    Michael Taylor

    Thursday, June 25, 2020 2:41 PM