Reading AssemblyInformationalVersion value from AssemblyInfo file with RegEx

為{幸葍}努か 提交于 2019-12-24 13:54:01

问题


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:


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



来源:https://stackoverflow.com/questions/14073582/reading-assemblyinformationalversion-value-from-assemblyinfo-file-with-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!