dansiegel / Mobile.BuildTools

The Mobile.BuildTools makes it easier to develop code bases in a clean, consistent, secure, and configurable way. Determine at Build which environment your app needs to run on, and what Client Secrets it should have. Plus many more amazing features!
http://mobilebuildtools.com
MIT License
228 stars 29 forks source link

Documentation for app.config transforms fails for similarly named keys #316

Closed Axemasta closed 1 year ago

Axemasta commented 1 year ago

Description

If you have 2 app config names that are similarly named (ie AppCenterAndroidSecret and AppCenterIosSecret) the config transforms will not be applied properly. The config transform is using Microsoft.Web.XmlTransform so that issue will be caused by that library, however the configuration of the XML can be updated in order to have both of these keys match.

Reproduction Steps

Steps to reproduce the behavior:

  1. Open the AppConfigSample solution
  2. Run the sample app (android or ios, i tested on ios but both platforms are affected)
  3. Try and apply the "Debug" transform
  4. The value for foo is not updated when xdt:Locator attribute is not present

Expected Behavior

The following replacements occur: Key Original Replacement
foo my foo transformedFoo
foo2 my bar transformedFoo2
image

Expected transformed XML document:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="foo" value="transformedFoo"/>
    <add key="foo2" value="transformedFoo2"/>
    <add key="Environment" value="Debug"/>
  </appSettings>
  <connectionStrings>
    <add name="test" providerName="my provider" connectionString="my connection string"/>
  </connectionStrings>
</configuration>

Actual Behavior

The value for foo is not replaced and instead is empty: Key Original Replacement
foo my foo
foo2 my bar transformedFoo2
image

Here is the transformed xml as it gets returned by TransformHelper (sb.ToString())

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="foo2" value="transformedFoo2"/>
    <add key="foo2" value="my bar"/>
    <add key="Environment" value="Debug"/>
  </appSettings>
  <connectionStrings>
    <add name="test" providerName="my provider" connectionString="my connection string"/>
  </connectionStrings>
</configuration>

Environment

Reproduction App

I have forked this repo and have a branch with a reproduction of the issue (app-config-repro)

Proposed Fix

Update the documentation & sample app to include the xdt:Locator attribute for the transform XML aswell as a note about this behaviour.

Axemasta commented 1 year ago

Closing after merge of #317

Remember if your config looks like this:

<configuration>
  <appSettings>
    <add key="foo" value="my foo" />
    <add key="foo2" value="my foo 2" />
  </appSettings>
</configuration>

You MUST use the xdt:Locator attribute otherwise your config will fail to load properly 😁

This is a valid replace transform
```xml ```
This is an invalid replace transform
```xml ```