Question:
I am trying to write a PowerShell script to update my .nuspec
file (nuget depdency) to the latest build version. I am having trouble with the wildcards though.
So I want to replace the version number of this line
1 2 |
to a new version number, i.e. version 2.2.2.2
1 2 |
My current place method looks like this. Note I need a wildcard as I have multiple nuget packages in the solution I need to replace, all follow the format of MyCompany.PackageName
1 2 |
$filecontent -replace 'id="MyCompany.*" version="*"', "$Version" | Out-File $file |
But this actually ends up creating
1 2 |
How do I modify my regex to ensure it replaces the version number component only?
Answer:
Replace with
1 2 |
$filecontent -replace 'id="MyCompany(.*?)" version=".*?"', "id=`"MyCompany`$1`" version=`"$Version`"" | Out-File $file |