0

I have the following PowerShell-Command which works perfectly fine when called from powershell directly:

Get-ChildItem -r -include 'AssemblyInfo.cs' `
| foreach-object { $a = $_.fullname; ( get-content $a ) `
| foreach-object { $_ -replace '((\[assembly:\sAssemblyVersion\(")(\d\.\d\.\d\.\d)("\)\]))', '$1[assembly:AssemblyInformationalVersion("$3-alpha")]' } ` 
| Out-File $_.fullname }

However, when called from cmd (our Buildservers-Process runs in cmd) it does not raise an error but it also does't replace the string as expected (it can be reproduced from any cmd-window):

PowerShell -Command "(Get-ChildItem -r -include  'AssemblyInfo.cs') | foreach-object { $a = $_.fullname; ( get-content $a ) | foreach-object { $_ -replace '((\[assembly:\sAssemblyVersion\(")(\d\.\d\.\d\.\d)("\)\]))', '$1[assembly:AssemblyInformationalVersion("$3-alpha")]' } | Out-File $_.fullname }"

I tried around with escaping quotation-marks and commands using and&` but it didn't help.

What am i missing out?

1 Answer 1

2

You have double quotes inside your command string:

... -replace '((\[assembly:\sAssemblyVersion\(")(\d\.\d\.\d\.\d)("\)\]))', ...
                                              ^                  ^

These must be escaped for CMD:

... -replace '((\[assembly:\sAssemblyVersion\(\")(\d\.\d\.\d\.\d)(\"\)\]))', ...
                                              ^^                  ^^
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.