简体   繁体   English

引用DLL,在Web API项目中不读取dll.config也不读取web.config

[英]Referenced DLL, in Web API project not reading dll.config nor web.config

This has been asked before, but I can't find an answer that works for me. 以前曾经问过,但我找不到适合我的答案。

I have a solution that contains 5 projects, one is a Web API (.net 4.5) and one is a Class Library (.net 4.5). 我有一个包含5个项目的解决方案,一个是Web API(.net 4.5),另一个是类库(.net 4.5)。 The Web API has a reference to the class/DLL. Web API具有对类/ DLL的引用。 In the class project, the Settings.settings is utilized to enter values in the App.Config. 在类项目中,Settings.settings用于在App.Config中输入值。 All the values in the settings are Type string, Scope Application, Access Modifier Internal. 设置中的所有值都是Type string,Scope Application,Access Modifier Internal。

These values are created in the App.Config and look something like this: 这些值在App.Config中创建,如下所示:

<applicationSettings>
<xxxxx.Properties.Settings>
  <setting name="setting1" serializeAs="String">
    <value>1</value>
  </setting>
  <setting name="setting2" serializeAs="String">
    <value>abc123</value>
  </setting>....

In the class code, the values are read like so: 在类代码中,值的读取方式如下:

Properties.Settings.Default.setting1;

When the package for the Web API is created, it has the .dll, but not the .dll.config file. 创建Web API的包时,它具有.dll,但不包含.dll.config文件。 If I manually copy the .dll.config file, the .dll doesn't read from it. 如果我手动复制.dll.config文件,.dll不会从中读取。 It also doesn't seem to read the ConnectionString fromt he web.config either. 它似乎也没有从web.config读取ConnectionString。

I need the DLL to read either the .dll.config or the Web APIs web.config file. 我需要DLL来读取.dll.config或Web API web.config文件。 I have tried several solutions posted in stackoverflow, but most seem updated/deprecated and/or throw errors when I tried them. 我已尝试在stackoverflow中发布了几个解决方案,但大多数似乎更新/弃用和/或在我尝试时抛出错误。

What is the current and correct approach to this issue, with .net 4.5? 使用.net 4.5,这个问题的当前和正确方法是什么?

Thanks 谢谢

I ended up deleting everything from the Settings.settings eliminating the 我最终删除了Settings.settings中删除的所有内容

<applicationSettings>
  <xxxxx.Properties.Settings>...

section of the App.Config. App.Config的一节。 Then I just added a regular <appSettings> section and calling the value in code with 然后我只添加了一个常规的<appSettings>部分并在代码中调用了值

ConfigurationManager.AppSettings["xxxxx"]; 

I read in some posts that this was no longer supported, but it was the method that worked for me. 我在一些帖子中读到这不再支持,但这是对我有用的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM