代码之家  ›  专栏  ›  技术社区  ›  grenade

以编程方式访问app.config的路径

  •  7
  • grenade  · 技术社区  · 14 年前

    我正在寻找一种从Windows服务可执行文件中以编程方式获取app.config文件路径的方法。 生成过程更改 App.config program-name.exe.config 我可以做如下的事情:

    var configFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "program-name.exe.config");
    

    但是,我正在寻找一些在运行时获取配置文件名的方法,这些方法不涉及将exe名称硬编码到应用程序中。ConfigurationManager有一些方法,因此它必须是可能的。

    1 回复  |  直到 14 年前
        1
  •  9
  •   Fredrik Mörk    14 年前

    我通常使用 AppDomain.CurrentDomain.SetupInformation.ConfigurationFile . 但没有在Windows服务上下文中尝试。