Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 88 lines (78 sloc) 4.042 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="GitDescribeToVersion" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<Describe ParameterType="System.String" Required="true" />
<Version ParameterType="System.String" Output="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.Reflection" />
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var m = Regex.Match(Describe, @"^([a-zA-Z]*)(?'Major'\d+)\.(?'Minor'\d+)(-(?'Revision'\d+))?");
if (m.Success)
{
var major = m.Groups["Major"].Value;
var minor = m.Groups["Minor"].Value;
var gr = m.Groups["Revision"];
var revision = gr.Success ? gr.Value : "0";
Version = major + "." + minor + "." + revision + ".0";
}
]]>
</Code>
</Task>
</UsingTask>
<PropertyGroup>
<GeneratedAssemblyInfo>$(IntermediateOutputPath)\__versioninfo.cs</GeneratedAssemblyInfo>
<GitDescribe>$(IntermediateOutputPath)\__gitinfo</GitDescribe>
<GitVersionCache>$(IntermediateOutputPath)\__gitlastknown</GitVersionCache>
<GitTagMatch Condition=" '$(GitTagMatch)' == '' ">*</GitTagMatch>
<HasForcedKey Condition=" '$(PrivateKeyName)' != '' Or '$(PrivateKeyPath)' != '' ">true</HasForcedKey>
</PropertyGroup>

<Target Name="GetGitVersionInfo">
<MakeDir Directories="$(IntermediateOutputPath)" ContinueOnError="true" />
<Exec Command="git describe --tags --match $(GitTagMatch) > $(GitDescribe)" IgnoreExitCode="true" />
<ReadLinesFromFile File="$(GitDescribe)">
<Output TaskParameter="Lines" PropertyName="_CurrentGitVersion"/>
</ReadLinesFromFile>
<ReadLinesFromFile File="$(GitVersionCache)" ContinueOnError="true">
<Output TaskParameter="Lines" PropertyName="_LastGitVersion"/>
</ReadLinesFromFile>
<CreateProperty Condition=" '$(_CurrentGitVersion)' == '' " Value="none0.0-yet">
<Output PropertyName="_CurrentGitVersion" TaskParameter="Value"/>
</CreateProperty>
</Target>

<!--
assembly info is only regenerated if the git repo changes
this speeds up local builds considerably
-->
<Target Name="CreateAssemblyInfoFromGit" Condition=" '$(_CurrentGitVersion)' != '$(_LastGitVersion)' Or '$(HasForcedKey)' == 'true' ">
<Delete Files="$(GeneratedAssemblyInfo)" />

<!--
cache the current git describe output
but only if we're not doing a release (signing with private keys) build
-->
<WriteLinesToFile File="$(GitVersionCache)" Lines="$(_CurrentGitVersion)" Overwrite="true" Condition="'$(HasForcedKey)' != 'true'"/>
<Delete Files="$(GitVersionCache)" Condition =" '$(HasForcedKey)' == 'true' " />

<GitDescribeToVersion Describe="$(_CurrentGitVersion)">
<Output TaskParameter="Version" PropertyName="_AssemblyVersion"/>
</GitDescribeToVersion>

<WriteLinesToFile File="$(GeneratedAssemblyInfo)" Overwrite="true"
Lines="
[assembly: System.Reflection.AssemblyFileVersion(&quot;$(_AssemblyVersion)&quot;)]
[assembly: System.Reflection.AssemblyTitle(&quot;$(_CurrentGitVersion)&quot;)]
[assembly: System.Reflection.AssemblyVersion(&quot;$(_AssemblyVersion)&quot;)]" />
<WriteLinesToFile File="$(GeneratedAssemblyInfo)" Overwrite="false"
Condition=" '$(PrivateKeyName)' != '' "
Lines="[assembly: System.Reflection.AssemblyKeyName(&quot;$(PrivateKeyName)&quot;)]" />
</Target>

<Target Name="BeforeBuild" DependsOnTargets="GetGitVersionInfo;CreateAssemblyInfoFromGit">
<Error Condition="!Exists('$(GeneratedAssemblyInfo)')" Text="The version info file is missing, although it should have been generated by the previous step." />
<CreateItem Include="$(GeneratedAssemblyInfo)">
<Output TaskParameter="Include" ItemName="Compile"/>
</CreateItem>
</Target>

<Target Name="BeforeClean">
<Delete Files="$(GeneratedAssemblyInfo);$(GitDescribe);$(GitVersionCache)" ContinueOnError="true" />
</Target>
</Project>
Something went wrong with that request. Please try again.