views:

331

answers:

3

Hii, there are many others had already post so many question about this..But here the scenario is different.

I need to extract the first three digits ie. $(major).$(Minor).$(Build) from version number. how can i do this??..i tried AssemblyInfo Task..but that task is just for overwriting the version number.not to extract the version number.

I need to extract first three number and assign them to some property.for further use.

well,i can overwrite them using FileUpdate task.like ::

< FileUpdate Files="@(AssemblyFile)" Regex='(\d+).(\d+).(\d+).(\d+)' ReplacementText='$1.$2.$3.$(Revision)'> < /FileUpdate>

now how can i use their value ie. $1,$2,$3 to assign to properties.???

Thanx.

A: 

The only solution is to write a custom build task, and parse the version number manually in the code.

Gerrie Schenck
Isn't there any other solution .??which i can done with regular expression?? or if there is any Task for it??
Divya mohan Singh
Well I've written my own task for it and I've used simple string methods to parse the version number but I'm sure you can do it with regex too. But you'll have to write your own task for this anyway, unless you find an out-of-the-box solution.
Gerrie Schenck
A: 

You can use MSBuild.Community.Tasks.AssemblyInfo.AssemblyVersion to access AssemblyVersion and AssemblyFileVersion from AssemblyInfo.cs.

Indeed this task can only be used to set the version.

Maybe this post is usefull.

Filburt
thanx filburt, but this task is not been used for reading the assemblyversion or assemblyfileversion. It can only overwrite them by the property.
Divya mohan Singh
Maybe this might help: http://weblogs.asp.net/dmckinstry/archive/2007/02/06/poor-man-s-assemblyinfo-check-in-msbuild.aspx
Filburt
A: 

I use the RegexMatch-task from the MSBuild.Community.Tasks.

You can write the output of the match to an itemgroup, although you want to read it into 3 properties, as above, a custom task would then be prefered.

Bart Janson