0

Here is a line in my xyz.csproj file:

<Reference Include="SomeDLLNameHere, Version=10.2.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />

All I need to do is replace the 'Version=10.2.6.0' to 'Version=11.0.0.0' .

The program I need to do this in is VSBuild which uses VBScript so I believe.

The problem is that I can't hardcode the 'old' version number. I therefore need to replace the following :

<Reference Include="SomeDLLNameHere, Version=10.2.6.0,

I therefor need a regex that will match the above bearing in mind that that in the example quoted, the 10.2.6.0 could be anything.

I believe that a regex that would select the text including and between

'<Reference Include="SomeDLLNameHere' and '>' is what I need.

There are other references to similar requests but none seem top work for me.

I would normally use C# to do this sort of thing and VBScript/Regex is something I avoid like the plague.

2
  • 2
    s/Version=[\d.]+/Version=11.0.0.0/g will replace every version number to your new one, dunno how you'd do it in VBScript though. Also, if people have helped you you should accept more answers. Commented Jun 28, 2011 at 2:59
  • Thanks inTide but there are many dll's referenced and I only need to update one of them, not all. Commented Jun 28, 2011 at 3:06

3 Answers 3

1

For most regex flavors, you would use this:

<Reference Include="SomeDLLNameHere.*?/>

For visual studio, I am not sure if the *? would work... Try this:

\<Reference Include="SomeDLLNameHere[^/]*\/\>
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the suggestion but I'm not doing this in code. I need just the bare regex.
Are you doing it in the find/replace dialog? That has a very different syntax.
0

This regex pattern should work

"(<Reference[^>]+Version=)([^,]+),"

Applied with VBScript

  str1 = "<Reference Include=""SomeDLLNameHere, Version=10.2.6.0,"

  ' Create regular expression.
  Set regEx = New RegExp
  regEx.Pattern = "(<Reference[^>]+Version=)([^,]+),"

  ' Make replacement.
  ReplaceText = regEx.Replace(str1, "$111.0.0.0,")
  WScript.echo ReplaceText

Gives the correct result

<Reference Include="SomeDLLNameHere, Version=11.0.0.0,

UPDATE

if you need something that matches between Version= and the end of the tag use > instead of ,

"(<Reference[^>]+Version=)([^>]+)>"

Comments

0

Using Regex with C# or VBScript is pretty much the same because it all comes to developing the regular expression. Something like this could help: <Reference\s+Include\s*=\s*\".+\",\s*Version\s*=\s*.+,

Not sure what are the rules about case sensitivity and white spaces in csproj files, but this covers the form you described previously. Note that the "+" operator means one or kleen.

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.