I'm currently authoring a new NuGet package, but I can't get the app.config.install.xdt file right (which is the xml file that transforms app.config to suit the installed package).
The problem is inserting a <configSections> section in app.config as the first child - but only in case it is missing!
It MUST be the first child, or the application will fail with an exception (Microsoft enforcement).
If I just use the regular “InsertIfMissing” transform, the insertion takes place after any existing children, so that seems a no-go.
What can I do to solve my problem?
You can utilize the attribute
xdt:Transform="InsertBefore"
to insert a new element in the section but before the any other element, like:Certificate: XDT Transform: InsertBefore - Locator Condition is ignored
And see How to use XDT in NuGet - Examples and Facts for some more details.
Hope this helps.