Reading AssemblyInformationalVersion value from As

2019-08-13 15:28发布

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?

1条回答
We Are One
2楼-- · 2019-08-13 16:12

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

查看更多
登录 后发表回答