简体   繁体   中英

Supply App.config file via NuGet

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?

I have currently done this:

  • mypackage.nupkg
    • content
      • App.config

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

So I want to combine my App.config with the user's 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.

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>

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

You do this using .transform files :

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 Package Transformations这个插图非常简单。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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