I have a package which applies app.config transformations upon project. Transform file looks like this
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="handlerId" value="$assemblyname$"/> <!--populate from project params-->
<--other params-->
</appSettings>
</configuration>
The case is: add package to a new project with no app.config, manually update app.config in project, and then update package.
If I include app.config.transform to my package nuget creates app.config in project, but if i change value of one of parameters and update/reinstall package it creates copy of that parameter with value of package instead of skipping it.
For example: Installed package upon clean project
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="handlerId" value="MyApp"/>
</appSettings>
</configuration>
Then changed handlerId value to MyApp1
and update package. The result of transformation is
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="handlerId" value="MyApp1"/>
<add key="handlerId" value="MyApp"/> <!--shouldn't appear!-->
</appSettings>
</configuration>
I tried to use xdt transformations instead. They work great upon package updating or installing package on project with app.config, but if there is no app.config nuget doesn't create it.
The .transform process doesn't distinguish the key or value attribute. They are both just attributes. Therefore, it doesn't realize that your particular change is inconsequential, and that it doesn't need to add the defined element again.
http://docs.nuget.org/docs/creating-packages/configuration-file-and-source-code-transformations
For all nuGet knows, the value="MyApp" may define something that is required for its particular package, and if that element + attribute(s) aren't there verbatim, the package wouldn't function.