-
Notifications
You must be signed in to change notification settings - Fork 2
/
Directory.Build.targets
46 lines (45 loc) · 2.37 KB
/
Directory.Build.targets
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
<Project>
<Target
Name="SetVersions"
BeforeTargets="GetAssemblyVersion;GetPackageVersion;InitializeSourceControlInformation"
Returns="Version;PackageVersion">
<Exec
Command="git for-each-ref --sort=taggerdate --format '%25(refname)' refs/tags"
ConsoleToMSBuild="true"
StandardOutputImportance="low">
<Output TaskParameter="ConsoleOutput" ItemName="GitOutput"/>
</Exec>
<ItemGroup>
<GitTag
Condition="$([System.Text.RegularExpressions.Regex]::IsMatch(%(Filename)%(Extension), '^v\d+\.\d+\.\d+(-\w+)?$'))"
Include="$([System.String]::Copy(%(GitOutput.Filename)%(GitOutput.Extension)).Substring(1))"/>
</ItemGroup>
<PropertyGroup>
<PackageVersion>%(GitTag.Identity)</PackageVersion>
</PropertyGroup>
<PropertyGroup>
<PackageVersion Condition="'$(PackageVersion)' == ''">0.0.0</PackageVersion>
<Version>$(PackageVersion)</Version>
</PropertyGroup>
<Message
Text="PackageVersion: $(PackageVersion)"
Importance="high"/>
</Target>
<Target
Name="SetPackageDescription"
BeforeTargets="GenerateNuspec"
Returns="PackageDescription">
<PropertyGroup>
<!-- Normalize \r\n to \n -->
<PackageDescription>$([System.Text.RegularExpressions.Regex]::Replace($(PackageDescription.Trim()), '\r\n', ' '))</PackageDescription>
<!-- Strip leading space from each line -->
<PackageDescription>$([System.Text.RegularExpressions.Regex]::Replace($(PackageDescription), '^[\t ]+', '', System.Text.RegularExpressions.RegexOptions.Multiline))</PackageDescription>
<!-- Temporarily convert paragraph breaks (\n\n) to a placeholder (\r\r) -->
<PackageDescription>$([System.Text.RegularExpressions.Regex]::Replace($(PackageDescription), '\n\n', ' ', System.Text.RegularExpressions.RegexOptions.Multiline))</PackageDescription>
<!-- Remaining \n should collapse into a single line -->
<PackageDescription>$([System.Text.RegularExpressions.Regex]::Replace($(PackageDescription), '\n', ' ', System.Text.RegularExpressions.RegexOptions.Multiline))</PackageDescription>
<!-- Convert placeholder \r\r back to \n\n -->
<PackageDescription>$([System.Text.RegularExpressions.Regex]::Replace($(PackageDescription), '\r', ' ', System.Text.RegularExpressions.RegexOptions.Multiline))</PackageDescription>
</PropertyGroup>
</Target>
</Project>