通过 NuGet 提供 App.config 文件 [英] Supply App.config file via NuGet

查看:36
本文介绍了通过 NuGet 提供 App.config 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have some information in my nupkg that I would like to include in the consumer's application. What is the best way to include a partial app.config directly when consuming the nupkg?

我目前已经这样做了:

  • mypackage.nupkg
    • 内容
      • App.config

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

      But this makes that it wants to override a user's own App.config, while there could be valuable information in there.

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

      So I want to combine my App.config with the user's App.config.

      我已经看到了这样的东西:C#:管理多个 App.config 文件,但我看不到如何强制用户将我的作品包含在其 App.config 中.

      I already saw something like this: C#: manage Multiple App.config files, but I cannot see how I could force the user to include my piece into its App.config.

      我的 App.config 文件的内容:

      Contents of my App.config file:

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

      How can I force the consumer to add my App.config to its own app.config?

      推荐答案

      你这样做 使用 .transform 文件:

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

      In NuGet's traditional way of configuration-file transformation, you add a file to your package's content and give it the same name as the file you want to transform, followed by a .transform extension. For example, to transform a web.config file, you create a web.config.transform file. The transformation file contains XML that looks like a web.config or app.config file, but it includes only the sections that need to be merged into the project's configuration file.

      这篇关于通过 NuGet 提供 App.config 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆