Supply App.config file via NuGet

痞子三分冷 提交于 2019-12-01 10:19:28

问题


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?


回答1:


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.




回答2:


check the post NuGet Package Transformations this illustrated very simple.



来源:https://stackoverflow.com/questions/34156388/supply-app-config-file-via-nuget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!