有什么用有默认的(组装).dll.config用于.NET的组件文件? [英] What use has the default (assembly).dll.config file for .NET-Assemblies?

查看:355
本文介绍了有什么用有默认的(组装).dll.config用于.NET的组件文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于在C#中的AppSettings的问题。
首先I'll形容我的处境。

I have a question regarding AppSettings in C#. First I´ll describe my situation.

我的解决方案由一个可执行程序的的Program.exe assembly.dll

My solution consists of an executable program program.exe and an assembly.dll.

程序引用组件并用它的作品。组装项目已经成立了与Visual Studio项目设置管理器应用程序的设置。现在,当我编译我在我的 assembly\bin\release 文件夹的解决方案有一个 assembly.dll.config 。文件,其中包含我刚才设置的设置

The program references the assembly and works with it. The assembly-project has application settings set up with the Visual Studio project settings manager. Now when I compile my solution in my assembly\bin\release folder there is an assembly.dll.config file which contains the settings I have set up earlier.

现在我不明白的东西:在这里我引用我的程序项目的 assembly.dll 我已经检查 CopyLocal = TRUE ,但在我的 program\bin\release 文件夹只存在 assembly.dll ,但不是assembly.dll.config文件,但仍是 assembly.dll 知道我在组装项目的应用程序设置中设置了设置。

Now the thing I don´t understand : in my program-project where I reference the assembly.dll I have checked CopyLocal=True, but in my program\bin\release folder there is only the assembly.dll but not the assembly.dll.config file BUT STILL the assembly.dll knows the settings I have set up in the assembly-project application settings.

现在我看了好几次组件始终可以访问可执行程序的设置,但程序没有相应的设置,所以为什么组装知道正确的设置时,有没有 assembly.dll.config 文件存在?

Now I have read several times that assemblies always access the settings of the executable program but the program has no corresponding settings, so why does the assembly know the correct settings when there is no assembly.dll.config file present?

我假设的设定在(当然)编译时被编译成汇编,但它没有任何意义,在我assembly\bin\release文件夹中有实际上是一个assembly.dll.config文件。

I assume the settings are compiled into the assembly at compiletime (of course), but then it makes no sense that in my assembly\bin\release folder there actually IS an assembly.dll.config file.

我尝试将该文件复制到我的 program\bin\release 文件夹,其中 assembly.dll 被复制到构建行动,但 assembly.dll 会忽略,如果有一个 assembly.dll的.config 文件存在于同一个文件夹。它总是从编译时使用的设置。我只是鸵鸟政策明白了 assembly.dll.config 文件。为什么创建时它从来没有对 assembly.dll's 行为的影响?

I tried copying this file into my program\bin\release folder where the assembly.dll is copied to on build action, but the assembly.dll just ignores if there is an assembly.dll.config file present in the same folder. It always uses the settings from compiletime. I just don´t understand the use of the assembly.dll.config file. Why is it created when it never has impact on the assembly.dll´s behaviour ?

推荐答案

默认值被内置到.dll文件。当然你也可以还更改这些设置,但你这样做,在配置的Program.exe,而不是通过引用组装设置在configSeconds / sectionGroup的部分。该组件设置就可以了的applicationSettings通过创建一个具有相同名称的部分一个XML块改变。

The default values are built into the .dll file. You can of course still change those settings, but you do that in the program.exe config instead by referring to the assembly settings with a section in configSeconds/sectionGroup. The assembly settings can then be changed in the applicationSettings by creating a XML block with the same name as the section.

节组中的节标记可以简单地从被复制您的组装项目的app.config文件。这样的道理,名字等,将是正确的。同样无二的applicationSettings一部分。 ,只要它在装配项目和进入的Program.exe项目的app.config文件中复制的app.config

The section tag in the section group can simply be copied from the app.config file of your assembly project. That way the token, name, etc. will be correct. The same goes for the applicationSettings part. Just copy it from the app.config in the assembly project and into the app.config file of the program.exe project.

例如program.exe.config:

example program.exe.config:

<configuration>
  <configSections>
    ... references to all dll settings ...
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="MyAssemblyNamespace.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  ... more config stuff...
  <applicationSettings>
    ... override your dll settings ...
    <MyAssemblyNamespace.Properties.Settings>
       <setting name="MaxUserNameLength" serializeAs="String">
          <value>100</value>
       </setting>
    </MyAssemblyNamespace.Properties.Settings>
  </applicationSettings>

这篇关于有什么用有默认的(组装).dll.config用于.NET的组件文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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