AnthillPro (Powershell Script) - Variable within single quote not getting resolved

159 Views Asked by At

I need help with a Powershell script I am writing within AnthillPro to automate updating release version number in my config file.

I am reading my Config file to find current version and then changing it with another value using 'gc' command.

The Problem is that the variable $currentRelease is not getting resolved in the first argument to 'gc' command since this is in single quote. I have tried using escape characters but unable to fix the issue.

How do I resolve $currentRelease to get the value stored in it? Please let me know your suggestions.

(Note that the variables configFolder, ConfigFilename, appSettingsNewValue & release are predefined properties within AntHillPro and are getting resolved correctly. No issue with these)

Update: I am now able to replace the required text successfully. However I am now running into an issue where the XML file formed after replacement is corrupted. There is some special character at the start of file. Please let me know if anyone has faced similar issue.

<project name="buildscript" default="create-file" basedir=".">
    <target name="create-file">
        <echo file="powershell.ps1" append="false">
            [xml] $xdoc = get-content ${configFolder}\${configFilename};
            $currentRelease = $xdoc.config_data.release;
            (gc "${configFolder}\${configFilename}") -replace '&lt;${release}&gt;${currentRelease}', '&lt;${release}&gt;${appSettingsNewValue}' | out-file "${configFolder}\${configFilename}"
        </echo>
    </target>
</project>
1

There are 1 best solutions below

0
On

Single-quoted strings won't expand variables in them. That's their point.