Github action variable substitution for xml connectionstring replacement

Viewed 360

I'm trying to replace the connectionString in an App.Config XML file for a WPF app based on prod/qa/dev environments. I'm trying to use the github actions variable substitution (https://github.com/marketplace/actions/variable-substitution) to do it.

The goal is to replace the following section with alternative sources:

        <add name="DefaultConnection"
             connectionString="Data Source=(LocalDb)\\MSDB;DbFilename=aspcore-local.mdf;" />

I was able to successfully change a simple json file, but how can this section be replaced in an XML file?

    - name: variable substitution in json
      uses: microsoft/variable-substitution@v1 
      with:
        files: 'test.xml'
      env:
        configuration.connectionStrings.DefaultConnection.connectionString: "test" ????
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <connectionStrings>
            <add name="DefaultConnection" connectionString="replaceme!"/>
        </connectionStrings>
    </configuration>

I initially thought to transform the file using https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/file-transform?view=azure-devops but that's only available in Azure DevOps vs. GitHub actions.

I know there is a better way, I just don't know what it is... thanks!

0 Answers
Related