Update project configuration file with powershell script doesn't work

Hi,

I’m using a powershell script to update some properties in configuration files of my projects. I pass the values by parameters to the script. When I call the scripts directly from a powershell command window, it works.
But when I call it from a Powershell Action in Continua CI it doesn’t work, the file is not changed.
I can’t find any error in the logs and the script terminate correctly.

Regards

Julien

Hi Julien,

If you could provide the details that you have entered into your PowerShell action, particularly showing how the Script Arguments are defined, and also your PowerShell script showing what type of arguments are required, then we should be able to help you further. Either post the details here or send to support@finalbuilder.com.


Seems to be a problem with the Quote and Code tags.

Hi,

The arguments in the powershell action are :
-file “$Source.AASharp$/Src/AASharp/AASharp.csproj” -assemblyVersion “%gitversion_assemblysemver%” -assemblyFileVersion “%gitversion_assemblysemfilever%” -nugetVersion “%gitversion_nugetversionv2%”

After execution, in the log I get :

Working Directory: D:\Tools\PowerShellScripts
Executable: C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe
Arguments: -NonInteractive -Command try { [string]$pathToScript = ‘D:\Tools\PowerShellScripts\updateVersionInCsproj.ps1’; [string]$arg1 = ‘D:\ContinuaCI\CI_AWS\Ws\6064\Source\AASharp/Src/AASharp/AASharp.csproj’; [string]$arg2 = ‘1.93.2.0’; [string]$arg3 = ‘1.93.2.0’; [string]$arg4 = ‘1.93.2’; invoke-expression -Command ‘& $pathToScript -file $arg1 -assemblyVersion $arg2 -assemblyFileVersion $arg3 -nugetVersion $arg4’; exit $lastexitcode } catch { $Error[0]; exit 1}

The powershell script I execute is :

Param(
[parameter(Mandatory=$true)][string]$file,
[parameter(Mandatory=$true)][string]$assemblyVersion,
[parameter(Mandatory=$true)][string]$assemblyFileVersion,
[parameter(Mandatory=$false)][string]$nugetVersion=""

)

$xml = New-Object -TypeName XML
$xml.Load($file)

if(![string]::IsNullOrEmpty($nugetVersion)) {
$xml.Project.PropertyGroup.Version = $nugetVersion
}

$xml.Project.PropertyGroup.AssemblyVersion = $assemblyVersion
$xml.Project.PropertyGroup.FileVersion = $assemblyFileVersion

$streamWriter = New-Object System.IO.StreamWriter($file, $false)

$xml.Save($streamWriter)
$streamWriter.Close()


If in a powershell console I execute

cd D:\Tools\PowerShellScripts
./updateVersionInCsproj.ps1 -file ‘D:\ContinuaCI\CI_AWS\Ws\6064\Source\AASharp/Src/AASharp/AASharp.csproj’ -assemblyVersion ‘1.93.2.0’ -assemblyFileVersion ‘1.93.2.0’ -nugetVersion ‘1.93.2’

it works, the values are updated in the file. But not when called by Continua CI

Regards

Hi Julien,

Is it possible that the file is being updated but then overwritten later in the build e.g. by the repository rules in the next stage?

Add Get-Content $file | foreach {Write-Output $_} to the end of the script or in another script called by subsequent action to see if the file has been changed.




Is it possible that the file is being updated but then overwritten later in the build e.g. by the repository rules in the next stage


That is the problem. I will have to change that.
Thanks