NuGet app.config XDT when target project has no app.config

I tried to package a nuget package that has an app.config.intall.xdt file. The xdt file must support XML-Document-Transform (XDT) .

If the target project that is going to install the nuget package has app.config, XDT will execute correctly, but the problem is, if the target project has no app.config, XDT will do nothing.

Is there a way to create an app.config file if the target project doesn't have a file when an XDT operation is needed?

The code below shows my xdt file 'app.config.intall.xdt' and if you want to try and install the nuget package that is causing the problem, run the following command in the nuget-packager console.

To install the nuget package

install-package Experiment.Xunit -version 2.0.0-pre08

      

app.config.intall.xdt

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <runtime xdt:Transform="InsertIfMissing">
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly xdt:Transform="InsertIfMissing"
                         xdt:Locator="Condition(_defaultNamespace:assemblyIdentity/@name='xunit.extensions')">
        <assemblyIdentity name="xunit.extensions" publicKeyToken="8d05b1bb7a6fdb6c" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.9.0.1566" newVersion="1.9.0.1566" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

      

+3


source to share


1 answer


You can use Install.ps1 or Init.ps1 hook provided by NuGet.

Create a powershell script file which, if app.config does not exist, creates it with default

Another way might be (I can't test it now) to add the app.config file with the desired value in the nuget packages content folder .

I think nuget will not overwrite the file if it is present in the project root.



--- Update ---

Nuget Documentation: Allow Users to Overwrite Preexisting Content Files

--- Update 2 ----

I did some tests: you can use Configuration File Transformations instead of XDT to have the desired behavior

+1


source







All Articles