通过 NuGet 提供 App.config 文件

Mar*_*nix 2 c# app-config nuget

我的 nupkg 中有一些信息,我想将其包含在消费者的应用程序中。使用 nupkg 时直接包含部分 app.config 的最佳方法是什么?

我目前已经这样做了:

  • mypackage.nupkg
    • 内容
      • 应用程序配置

但这使得它想要覆盖用户自己的 App.config,而其中可能存在有价值的信息。

所以我想将我的 App.config 与用户的 App.config 结合起来。

我已经看到了这样的内容:C#: 管理多个 App.config 文件,但我不知道如何强制用户将我的部分包含到其 App.config 中。

我的 App.config 文件的内容:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="somefolder;someotherfolder;" />
    </assemblyBinding>
  </runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)

如何强制消费者将我的 App.config 添加到自己的 app.config 中?

stu*_*rtd 5

您可以使用 .transform 文件来执行此操作:

在 NuGet 的传统配置文件转换方式中,您将一个文件添加到包的内容中,并为其指定与要转换的文件相同的名称,后跟 .transform 扩展名。例如,要转换 web.config 文件,您需要创建一个 web.config.transform 文件。转换文件包含看起来像 web.config 或 app.config 文件的 XML,但它仅包含需要合并到项目配置文件中的部分