【问题标题】:Supply App.config file via NuGet通过 NuGet 提供 App.config 文件
【发布时间】:2016-03-13 09:39:47
【问题描述】:

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

我目前已经这样做了:

  • mypackage.nupkg
    • 内容
      • App.config

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

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

我已经看到了类似这样的内容:C#: manage Multiple App.config files,但我看不出如何强制用户将我的作品包含在其 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>

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

【问题讨论】:

    标签: c# nuget app-config


    【解决方案1】:

    你这样做using .transform files

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

    【讨论】:

      【解决方案2】:

      查看NuGet Package Transformations这个贴图很简单。

      【讨论】:

      • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会失效。
      猜你喜欢
      • 2011-06-03
      • 1970-01-01
      • 1970-01-01
      • 2016-03-28
      • 1970-01-01
      • 1970-01-01
      • 2015-12-04
      • 2011-01-27
      • 2014-08-26
      相关资源
      最近更新 更多