我正在编写一个 .NET DLL (C#),它是第 3 方产品的插件。该产品在其 application.exe.config 文件中包含此内容:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
我的 DLL 以 .NET v3.5 为目标,我的 app.config 文件包括以下内容:
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="myDLL.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
当我使用 Settings 对象(从 ApplicationsSettingsBase 派生)保存设置时,保存工作 - 数据保存到主机应用程序的 user.config 文件中。但是,它保存在其中(注意版本 = 4.0.0.0):
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="myDLL.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="anotherVendorsDLL.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
保存这些设置后,我的 DLL 将不会在主机应用程序的后续运行中加载设置。application.exe.config 的supportedRuntime 对此有影响 - 更改或删除它将意味着 user.config 文件以不同的 Version=XXXX 保存。使用 Version=2.0.0.0 我的设置加载得很好。
如何在不更新主机 application.exe.config 文件的情况下毫无问题地加载/保存我的设置?或者我是否需要考虑为我的应用程序设置使用替代存储位置,例如我自己的 XML 配置文件或注册表?