使用RegEx从AssemblyInfo文件中读取AssemblyInformationalVersion值 [英] Reading AssemblyInformationalVersion value from AssemblyInfo file with RegEx

查看:53
本文介绍了使用RegEx从AssemblyInfo文件中读取AssemblyInformationalVersion值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用msbuild从AssemblyInfo文件中读取AssemblyInformationalVersion,但是到目前为止,我还是失败了.下面的一个让我知道数字,但是我需要在引号内输入整个内容:

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))"/>

这是目标行,例如:

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

有什么主意吗?

推荐答案

如果只需要引号的内容,则应该可以使用如下表达式来获取它:

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

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

我猜想您可以在msbuild正则表达式中使用正向查找/向后查找.

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

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

这篇关于使用RegEx从AssemblyInfo文件中读取AssemblyInformationalVersion值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆