Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

88 lines (78 sloc) 4.042 kb
<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="none1.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>
Jump to Line
Something went wrong with that request. Please try again.