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

查看:270
本文介绍了通过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
      • mypackage.nupkg
        • content
          • 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天全站免登陆