1+ <?xml version =" 1.0" encoding =" utf-8" ?>
2+ <Project xmlns =" http://schemas.microsoft.com/developer/msbuild/2003" >
3+
4+ <UsingTask
5+ TaskName =" GenerateVersion"
6+ TaskFactory =" CodeTaskFactory"
7+ AssemblyFile =" $(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
8+
9+ <ParameterGroup >
10+ <SolutionInfoFile ParameterType =" System.String" Required =" true" />
11+ <GeneratedVersion ParameterType =" System.String" Output =" true" />
12+ </ParameterGroup >
13+ <Task >
14+ <Using Namespace =" System" />
15+ <Using Namespace =" System.IO" />
16+ <Using Namespace =" System.Text.RegularExpressions" />
17+ <Code Type =" Fragment" Language =" cs" >
18+ <![CDATA[
19+ var str = File.ReadAllText(this.SolutionInfoFile);
20+ var regex = new Regex(@"Version = ""([\d]+\.[\d]+\.[\d]+.[\d]+)""");
21+ var v = Version.Parse(regex.Match(str).Groups[1].Value);
22+ this.GeneratedVersion = String.Format("{0}.{1}.{2}.{3}", v.Major, v.Minor, v.Build, DateTimeOffset.UtcNow.ToUnixTimeSeconds());
23+ ]]>
24+ </Code >
25+ </Task >
26+ </UsingTask >
27+
28+ <Target Name =" GenerateVersionFile"
29+ Condition =" $(SkipPackage) != 'Skip'"
30+ AfterTargets =" CoreCompile"
31+ Inputs =" $(SolutionDir)\src\common\SolutionInfo.cs"
32+ Outputs =" $(SolutionDir)\build\version" >
33+ <GenerateVersion SolutionInfoFile =" $(SolutionDir)\src\common\SolutionInfo.cs" >
34+ <Output TaskParameter =" GeneratedVersion" PropertyName =" GeneratedVersion" />
35+ </GenerateVersion >
36+
37+ <Message Text =" Generating file '$(SolutionDir)\build\version' with version '$(GeneratedVersion)'" />
38+
39+ <WriteLinesToFile File =" $(SolutionDir)\build\version" Lines =" $(GeneratedVersion)" Overwrite =" True" />
40+ </Target >
41+
42+ <Target Name =" GetBuildVersion" Returns =" $(BuildVersion)" DependsOnTargets =" GenerateVersionFile" >
43+ <ReadLinesFromFile File =" $(SolutionDir)\build\version" >
44+ <Output TaskParameter =" Lines" PropertyName =" BuildVersion" />
45+ </ReadLinesFromFile >
46+ </Target >
47+ </Project >
0 commit comments