库项目中的.Net app.config [英] .Net app.config in library project

查看:18
本文介绍了库项目中的.Net app.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个解决方案中有一个控制台应用程序项目和库项目 (dll).库项目有 app.config 文件,我将连接字符串存储到数据库中.控制台应用程序引用此 dll.

I have a console application project and library project (dll) in one solution. The library project has app.config file where I store a connection string to database. The console application references this dll.

当我编译控制台应用程序并将其与库一起部署时,当我需要在部署应用程序后更改连接字符串时,我无法访问属于 dll 的 app.config 文件.

When I compile the console application and deploy it with the library I am not able to access the app.config file that belongs the dll when I need to change the connection string after the application is deployed.

这是我看到的文件,但不是 .config 文件:

This are the files that I see, but not .config file:

  • library.dll
  • library.pdb
  • 控制台应用程序
  • 控制台.exe
  • console.exe.manifest
  • 控制台.pdb
  • console.vshost.application
  • console.vshest.exe

我哪里做错了?

推荐答案

默认情况下,一个正在运行的应用程序只有 1 个.config"文件.它是与启动程序的 EXE 关联的.config"文件.您可能应该将 DLL 配置文件中的配置值复制到控制台应用程序的配置文件中.如果你真的想让它们分开,那么你不能使用默认的 ConfigurationSettings.AppSettings 字典.有关详细信息,请参阅此问题.

By default, there is only 1 ".config" file for a running application. It is the ".config" file associated with the EXE that started the program. You should probably copy the config values from the DLL's config file into the console app's config file. If you really want to keep them separate then you can't use the default ConfigurationSettings.AppSettings dictionary. See this question for more info.

这篇关于库项目中的.Net app.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆