loresoft/msbuildtasks

Task to return semver information for Git

joshgo opened this issue · 1 comments

Hi @pwelter34

There is a class GitDescribe that I can use to get the Tag value of a commit. I would like to use this value for my AssemblyVersion which has the format "x.x.x.x" (x must be numeric). The value returned by GitDescribe.Tag doesn't fit that format since it appends some hyphens, commit count, and the hash.

Example value of GitDescribe.Tag is v0.6.1.0-30-g19f3f2e7390b41384dcd9261c7e71aa902c06307

Is there a way for me to retrieve only the value "0.6.1.0" ?
Is there something already that exists that does this?

If not, would it make sense to have a specific class to parse the tag, and return you the semantic version information? The class could return the semver in one string, or it could return the Major, Minor, and Patch as individual properties.

Example :

public class GitSemver : GitClient
{
    [Output]
    public string Semver { get; set; }
    [Output]
    public string Major { get; set; }
    [Output]
    public string Minor { get; set; }
    [Output]
    public string Patch { get; set; }

   ...
}

Ok this was a silly request. Using the existing Git and Regex tasks, you can get the semantic version.

Example:

<GitDescribe LocalPath="$(MSBuildProjectDirectory)">
  <Output TaskParameter="Tag" PropertyName="Tag" />
</GitDescribe>
<RegexReplace Input="$(Tag)" Expression="^v([0-9]*)\.([0-9]*)\.([0-9]*)" Replacement="$1.$2.$3">
  <Output ItemName="Semver" TaskParameter="Output" />
</RegexReplace>

And then the assemblyInfo can be set:

<AssemblyInfo AssemblyVersion="@(Semver)" AssemblyFileVersion="@(Semver)"/>

Edit:
Mixed up the @ and $ in 2 lines.

  1. RegexReplace @(Tag) changed to $(Tag)
  2. Replacement string \1.\2.\3 changed to $1.$2.$3
  3. AssemblyInfo $(Semver) changed to @(Semver)