-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassemblyVersions.targets
More file actions
77 lines (61 loc) · 3.19 KB
/
assemblyVersions.targets
File metadata and controls
77 lines (61 loc) · 3.19 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
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<AssemblyVersion>$(MajorVerNum).$(MinorVerNum).0.0</AssemblyVersion>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
</PropertyGroup>
<!-- retrieve the revision count from Git and use it as the build number. If an error occurs
fallback to the default value
-->
<Target Name="AddGitRevCountToFileVersion" BeforeTargets="GetAssemblyVersion" Returns="FileVersion">
<Exec ConsoleToMsBuild="true" Command="git rev-list HEAD --count" ContinueOnError="true">
<Output TaskParameter="ConsoleOutput" PropertyName="gitRevCount" />
<Output TaskParameter="ExitCode" PropertyName="gitExitCode"/>
</Exec>
<PropertyGroup Condition="$(gitExitCode) == '0'">
<revVerNum>$(gitRevCount)</revVerNum>
<FileVersion>$(MajorVerNum).$(MinorVerNum).$(revVerNum).$(buildVerNum)</FileVersion>
</PropertyGroup>
</Target>
<!-- if we failed to retrieve the git rev count, use 0 or any initial value -->
<Target Name="FallbackFileVersion" Condition="$(gitExitCode) != '0'" AfterTargets="AddGitRevCountToFileVersion">
<PropertyGroup>
<FileVersion>$(MajorVerNum).$(MinorVerNum).$(revVerNum).$(buildVerNum)</FileVersion>
</PropertyGroup>
</Target>
<Target Name="SaveVersionFile" AfterTargets="Build">
<!-- Write the new version back to Version.txt -->
<WriteLinesToFile File="$(VersionFile)" Lines="$(FileVersion)" Overwrite="true" />
</Target>
<!-- increment the version number using a simple text file to keep the last version info -->
<Target Name="IncrementBuildNumber" BeforeTargets="BeforeBuild">
<PropertyGroup>
<VersionFile>$(ProjectDir)builtVersion.txt</VersionFile>
</PropertyGroup>
<!-- Read the last version number -->
<ReadLinesFromFile File="$(VersionFile)">
<Output TaskParameter="Lines" ItemName="versionLine"/>
</ReadLinesFromFile>
<Message Text="Current version from $(VersionFile) is: @(versionLine)"/>
<PropertyGroup>
<FullVersion>%(versionLine.Identity)</FullVersion>
<LastBuildVerNum>$([System.Text.RegularExpressions.Regex]::Match($(FullVersion), '^(\d+)\.(\d+)\.(\d+)\.(\d+)$').Groups[4].Value)</LastBuildVerNum>
<!-- Increment the revision number -->
<buildVerNum>$([MSBuild]::Add($([System.Int32]::Parse($(LastBuildVerNum))), 1))</buildVerNum>
</PropertyGroup>
</Target>
<PropertyGroup>
<HaveDotNetLegacy>$([MSBuild]::VersionLessThan('$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)'))','4.5'))</HaveDotNetLegacy>
<!--<Message Importance="High" Text="Building for NET legacy: $(HaveDotNetLegacy)"/>-->
</PropertyGroup>
<ItemGroup Condition="'$(HaveDotNetLegacy)' == 'false'">
<!-- add a metadata 'BuildDate'
https://learn.microsoft.com/en-us/dotnet/standard/assembly/set-attributes-project-file
-->
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
<_Parameter1>BuildDate</_Parameter1>
<_Parameter2>$([System.DateTime]::UtcNow.ToString('u'))</_Parameter2>
</AssemblyAttribute>
</ItemGroup>
</Project>