LoginSignup
2
1

More than 5 years have passed since last update.

dllのconfig

Posted at

dllのconfigに関して

調べて分かったことを列挙する。

  • dllのconfigの値を変更しても、変更は反映されない。
  • dllのconfigを削除しても、exeは実行できる。
  • dllにはビルド時の値が設定される。
  • 下記の構成の場合には、ビルド時の値 "hello, world." が設定される。

A (exe)

csharp: Form.cs
string text = new Lib().GetText();
label1.Text = text; // hello, world.

B (dll)

csharp: B.dll.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="B.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<B.Properties.Settings>
<setting name="Text" serializeAs="String">
<value>hello, world.</value>
</setting>
</B.Properties.Settings>
</applicationSettings>
</configuration>

csharp: Lib.cs
namespace B
{
public class Lib
{
public string GetText()
{
return Properties.Settings.Default.Text;
}
}
}

変更を反映するには?

exeのconfigにdllのconfigをマージすればよい。
configの値が設定されるようになり、変更が反映される。

AのconfigにBのconfigをマージしたものを下記に示す。

csharp: A.exe.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="B.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>
<applicationSettings>
<B.Properties.Settings>
<setting name="Text" serializeAs="String">
<value>hello, world. hello, world.</value>
</setting>
</B.Properties.Settings>
</applicationSettings>
</configuration>

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1