Search code examples
nugetconfiguration-filesxdt-transformxdt

How to use XDT on NuGet install if there is no config file already there?


Admittedly this is a corner case.

However, I have developed some XDT install and uninstall transforms that work very well for my NuGet package installation and uninstallation. All good there.

However, in the case where the consuming project does not itself already have an app.config file (or web.config file) when the package is installed, there are no warnings or complaints, but it doesn't actually create a new-from-scratch config file with the "stuff" in it that I want.

How can you use XDT to create a new config file from scratch if there isn't one already there to transform?


Solution

  • Simple fix seems to be to include an app.config.transform in addition to the app.config.install.xdt. All the work goes in the xdt file, and the app.config.transform has only the basic shell of an app.config file, namely:

    <configuration/>
    

    This seems to cause an app.config file to be created if one isn't there, but it doesn't overwrite one that is there, and then the xdt transform gets applied to that.