当主机应用程序通过其 app.config 定位不同版本时,我的外接程序 DLL 的 System.Configuration.dll 的特定版本?

发布于 2024-10-20 13:07:58 字数 1978 浏览 1 评论 0原文

我正在编写一个 .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 配置文件或注册表?

I'm writing a .NET DLL (C#) that is an add-in for a 3rd party product. That product includes this in it's application.exe.config file:

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v4.0"/>
</startup>

My DLL targets .NET v3.5, and my app.config file includes this:

<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>

When I use the Settings object (derived from ApplicationsSettingsBase) to save a setting, the save works - and the data is saved to the user.config file of the host application. However, it is saved with this in it (note the Version=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>

With these settings saved, my DLL will not load the settings on subsequent runs of the host application. The supportedRuntime of the application.exe.config has an impact on this - changing or deleting it will mean that the user.config file is saved with a different Version=X.X.X.X in it. With Version=2.0.0.0 my settings load just fine.

How can I get my settings to load/save without a problem without updating the host application.exe.config file? Or do I need to consider using an alternative storage location for my application settings, such as my own XML config file or registry?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫南 2024-10-27 13:07:58

这个问题缺少一些东西。 DLL 不能有自己的 .config 文件,其配置部分必须合并到 app.exe.config 文件中。在我看来,你无法控制这个文件,如何防止应用程序的所有者在重新安装或更新他的 .config 文件时破坏你?

无论如何,你缺乏控制力是非常麻烦的。强烈建议存储您自己的设置而不使用 .config 文件。 .xml 文件就可以了。

There's something missing from this question. A DLL cannot have its own .config file, its configuration sections must be merged into the app.exe.config file. Sounds to me you don't control this file, how do you prevent the owner of the app from breaking you when he reinstalls or updates his .config file?

At any rate, the lack of control you have is very troublesome. Storing your own settings without using a .config file is strongly indicated. An .xml file will do just fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文