# Update project configuration file with powershell script doesn't work

**URL:** <https://www.finalbuilder.com/forums/t/update-project-configuration-file-with-powershell-script-doesnt-work/5615>\
**Category:** Discussion\
**Created:** [March 11, 2018, 7:45am UTC](https://www.finalbuilder.com/forums/t/update-project-configuration-file-with-powershell-script-doesnt-work/5615 "2018-03-11T07:45:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![juts](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/juts/32/179_2.png) [@juts](https://www.finalbuilder.com/forums/u/juts)\
**Post date:** [March 11, 2018, 7:45am UTC](https://www.finalbuilder.com/forums/t/update-project-configuration-file-with-powershell-script-doesnt-work/5615/1 "2018-03-11T07:45:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)\
**Post date:** [March 12, 2018, 11:36am UTC](https://www.finalbuilder.com/forums/t/update-project-configuration-file-with-powershell-script-doesnt-work/5615/2 "2018-03-12T11:36:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![juts](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/juts/32/179_2.png) [@juts](https://www.finalbuilder.com/forums/u/juts)\
**Post date:** [March 14, 2018, 10:36am UTC](https://www.finalbuilder.com/forums/t/update-project-configuration-file-with-powershell-script-doesnt-work/5615/3 "2018-03-14T10:36:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sparky](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/sparky/32/10_2.png) [@Sparky](https://www.finalbuilder.com/forums/u/Sparky)\
**Post date:** [March 14, 2018, 11:57am UTC](https://www.finalbuilder.com/forums/t/update-project-configuration-file-with-powershell-script-doesnt-work/5615/4 "2018-03-14T11:57:22Z")

</div>

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&nbsp;Get-Content $file&nbsp;| 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.

---

<div class="post-metadata">

**Author:** ![juts](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/juts/32/179_2.png) [@juts](https://www.finalbuilder.com/forums/u/juts)\
**Post date:** [March 14, 2018, 1:41am UTC](https://www.finalbuilder.com/forums/t/update-project-configuration-file-with-powershell-script-doesnt-work/5615/5 "2018-03-14T01:41:04Z")

</div>

> 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
