简体   繁体   English

通过NuGet提供App.config文件

[英]Supply App.config file via NuGet

I have some information in my nupkg that I would like to include in the consumer's application. 我在我的nupkg中有一些信息,我想在消费者的应用程序中包含这些信息。 What is the best way to include a partial app.config directly when consuming the nupkg? 在使用nupkg时直接包含部分app.config的最佳方法是什么?

I have currently done this: 我目前这样做了:

  • mypackage.nupkg 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,而那里可能存在有价值的信息。

So I want to combine my App.config with the user's App.config. 所以我想将我的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. 我已经看到过这样的东西: C#:管理多个App.config文件 ,但我看不出如何强迫用户将我的文件包含到它的App.config中。

Contents of my App.config file: 我的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>

How can I force the consumer to add my App.config to its own app.config? 如何强制用户将App.config添加到自己的app.config中?

You do this using .transform files : 您可以使用.transform文件执行此操作

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. 在NuGet传统的配置文件转换方式中,您可以将文件添加到包的内容中,并为其提供与要转换的文件相同的名称,后跟.transform扩展名。 For example, to transform a web.config file, you create a web.config.transform file. 例如,要转换web.config文件,请创建web.config.transform文件。 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 . 转换文件包含看起来像web.config或app.config文件的XML,但它只包含需要合并到项目配置文件中的部分

检查NuGet Package Transformations这个插图非常简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM