提出问题提出问题
 

问题Using embedded App.Config

  • 2009年11月4日 10:00TheLearner 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    What are the consequences of making an App.Config file an embedded resource?

    When accessing the config file will it check both the calling application's config file as well as its own embedded app.config file or how does it work?

全部回复

  • 2009年11月4日 11:09Marcel Roma 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    You could surely embed an app.config in your executable and then use reflection etc. to use the settings in a read-only manner, but why would you want to do that when you can easily read the settings directly through the Settings class (even without deploying your app.config)?

    If you need to use specific configuration data with your libraries, use ConfigurationManager.OpenExeConfiguration().

  • 2009年11月4日 13:53TheLearner 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    I am referencing a web service which requires certain settings in the App.Config file, but I don't want the calling application to have this information in its app.config file, I want my dll to have it and access it.  Do you know what I mean?
  • 2009年11月4日 13:56David M MortonMVP, 版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    If you want a specific app.config for a dll, make one.

    Name it according to the dll, and not according to the main executable:

    SomeAssembly.dll.config

    This won't be accessible to the calling application.
    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiLinkedInForumsBrowser
  • 2009年11月4日 14:22Marcel Roma 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Use ConfigurationManager.OpenExeConfiguration() from within your library to open the configuration file as needed. If your concern is about confidentiality, why not encrypt/obfuscate the section containing the sensitive data?

    Maybe I don't get it right, but after all, what's the use of a read-only configuration that never changes and is not accessible from outside the executable (library)? You could as well create an internal custom class exposing the properties you need.
  • 2009年11月4日 15:40TheLearner 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    So when the calling application accesses the dll which in turn accesses the web service, it will check the SomeAssembly.dll.config?
  • 2009年11月4日 15:45David M MortonMVP, 版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Well, the web service is on the web.  But anytime the DLL tries to get values from the configuration, it'll first try the configuration file that matches it's own assembly name.  (SomeAssembly.dll.config).  If that doesn't exist, then it'll move to the executable's name.
    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiLinkedInForumsBrowser
  • 2009年11月4日 16:01jgalley 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    It might be cleaner to use two projects within your solution.  one for your client app and one for the web service.  There would be no confusion then
  • 2009年11月12日 11:21TheLearner 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    I have tried that it doesn't seem to work.

    I have removed the web service config from the unit test assembly's app.config.

    I have then renamed the app.config file in the assembly which has the web service reference to Tapi.Core.dll.config (the assembly name is Tapi.Core)

    Now when I run the unit test it fails because it cannot find the web service reference config information.
  • 2009年11月12日 13:47David M MortonMVP, 版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Yep.  Unit tests are their own beast.  You'll need another app.config file named after the unit test dll.   

    Tapi.UnitTests.dll.config or something similar (assuming the compiled unit test assembly is called "Tapi.UnitTests.dll"). 

    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiLinkedInForumsBrowser
  • 2009年11月12日 14:45TheLearner 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    I think we are talking about different things.

    A = The assembly which contains the web reference
    B = The assembly which calls A e.g. a website or a unit test assembly

    I want A to read ITS OWN app.config file for settings it requires.

    So when B calls A, A looks in its own App.Config file web service settings and executes.