tugberk
tugberk

Reputation: 58444

Reading AssemblyInformationalVersion value from AssemblyInfo file with RegEx

I'm trying to read the AssemblyInformationalVersion from the AssemblyInfo file with msbuild but I am failing so far. The below one gets me the digits but I need to whole input inside quotes:

<PropertyGroup>
  <Pattern>\[assembly: AssemblyInformationalVersion\(.(\d+)\.(\d+)\.(\d+)</Pattern>
  <In>@(ItemsFromFile)</In>
  <Out>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern)))</Out>
</PropertyGroup>

<Message Text="Output : $(Out.Remove(0, 41))"/>

This is the target line for example:

[assembly: AssemblyInformationalVersion("0.3.0-pre01")]

Any idea?

Upvotes: 1

Views: 757

Answers (1)

Mike Wade
Mike Wade

Reputation: 1746

If you just need the contents of the quotes you should be able to grab it with an expression like this:

(?<=\[assembly: AssemblyInformationalVersion\(").*(?="\)\])

I presume you can use positive lookahead/lookbehind in msbuild regexes.

Positive lookahead and lookbehind respectivly:

Match this(?=Where this is present ) (?<=Where this is present )Match this

Upvotes: 1

Related Questions