|
1 |
| -<Project TreatAsLocalProperty="TaskAssembly"> |
2 |
| - |
3 |
| - <PropertyGroup> |
4 |
| - <TaskAssembly>$(MSBuildThisFileDirectory)..\tasks\netstandard2.0\GitBuildInfo.dll</TaskAssembly> |
5 |
| - </PropertyGroup> |
6 |
| - |
7 |
| - <UsingTask TaskName="GitBuildInfo.GitInfoTask" AssemblyFile="$(TaskAssembly)" /> |
8 |
| - |
9 |
| - <Target Name="GitBuildInfo" AfterTargets="BeforeBuild"> |
10 |
| - <GitInfoTask ProjectDir="$(MSBuildProjectDirectory)"> |
11 |
| - <Output TaskParameter="GitHead" PropertyName="GitHead" /> |
12 |
| - <Output TaskParameter="CommitHash" PropertyName="CommitHash" /> |
13 |
| - <Output TaskParameter="GitBranch" PropertyName="GitBranch" /> |
14 |
| - </GitInfoTask> |
15 |
| - </Target> |
16 |
| - |
17 |
| -</Project> |
| 1 | +<Project TreatAsLocalProperty="GitHead;CommitHash;GitBranch"> |
| 2 | + |
| 3 | + <Target Name="GitBuildInfo" AfterTargets="BeforeBuild"> |
| 4 | + <Message |
| 5 | + Importance="high" |
| 6 | + Text="Getting build info from git" |
| 7 | + Condition="'$(GitHead)' == '' AND '$(CommitHash)' == '' AND '$(GitBranch)' == ''" /> |
| 8 | + <Exec |
| 9 | + Command="git describe --all --always --dirty" |
| 10 | + WorkingDirectory="$(MSBuildProjectDirectory)" |
| 11 | + ConsoleToMSBuild="true" |
| 12 | + IgnoreExitCode="true" |
| 13 | + Condition="'$(GitHead)' == ''"> |
| 14 | + <Output TaskParameter="ConsoleOutput" PropertyName="GitHead" /> |
| 15 | + </Exec> |
| 16 | + <Exec |
| 17 | + Command="git rev-parse --short HEAD" |
| 18 | + WorkingDirectory="$(MSBuildProjectDirectory)" |
| 19 | + ConsoleToMSBuild="true" |
| 20 | + IgnoreExitCode="true" |
| 21 | + Condition="'$(GitHead)' == ''"> |
| 22 | + <Output TaskParameter="ConsoleOutput" PropertyName="CommitHash" /> |
| 23 | + </Exec> |
| 24 | + <Exec |
| 25 | + Command="git name-rev --name-only HEAD" |
| 26 | + WorkingDirectory="$(MSBuildProjectDirectory)" |
| 27 | + ConsoleToMSBuild="true" |
| 28 | + IgnoreExitCode="true" |
| 29 | + Condition="'$(GitHead)' == ''"> |
| 30 | + <Output TaskParameter="ConsoleOutput" PropertyName="GitBranch" /> |
| 31 | + </Exec> |
| 32 | + <WriteLinesToFile |
| 33 | + File="$(IntermediateOutputPath)\githead.txt" |
| 34 | + Lines="$(GitHead)" |
| 35 | + Condition="'$(GitHead)' != ''" |
| 36 | + Overwrite="true" |
| 37 | + WriteOnlyWhenDifferent="true" /> |
| 38 | + <WriteLinesToFile |
| 39 | + File="$(IntermediateOutputPath)\git_head.txt" |
| 40 | + Lines="Not a git clone or git is not in Path." |
| 41 | + Condition="'$(GitHead)' == ''" |
| 42 | + Overwrite="true" |
| 43 | + WriteOnlyWhenDifferent="true" /> |
| 44 | + <WriteLinesToFile |
| 45 | + File="$(IntermediateOutputPath)\git_commit_hash.txt" |
| 46 | + Lines="$(CommitHash)" |
| 47 | + Condition="'$(CommitHash)' != ''" |
| 48 | + Overwrite="true" |
| 49 | + WriteOnlyWhenDifferent="true" /> |
| 50 | + <WriteLinesToFile |
| 51 | + File="$(IntermediateOutputPath)\git_commit_hash.txt" |
| 52 | + Lines="Not a git clone or git is not in Path." |
| 53 | + Condition="'$(CommitHash)' == ''" |
| 54 | + Overwrite="true" |
| 55 | + WriteOnlyWhenDifferent="true" /> |
| 56 | + <WriteLinesToFile |
| 57 | + File="$(IntermediateOutputPath)\git_branch.txt" |
| 58 | + Lines="$(GitBranch)" |
| 59 | + Condition="'$(GitBranch)' != ''" |
| 60 | + Overwrite="true" |
| 61 | + WriteOnlyWhenDifferent="true" /> |
| 62 | + <WriteLinesToFile |
| 63 | + File="$(IntermediateOutputPath)\git_branch.txt" |
| 64 | + Lines="Not a git clone or git is not in Path." |
| 65 | + Condition="'$(GitBranch)' == ''" |
| 66 | + Overwrite="true" |
| 67 | + WriteOnlyWhenDifferent="true" /> |
| 68 | + </Target> |
| 69 | + |
| 70 | + <ItemGroup> |
| 71 | + <!-- |
| 72 | + Add the namespace for the generated attribute to the global usings list only if the C# language version is 10.0 or newer. |
| 73 | + --> |
| 74 | + <Using Include="Elskom.Generic.Libs" Condition="'$(ImplicitUsings)' == 'enable'" /> |
| 75 | + <!-- |
| 76 | + Add the root namespace to the global usings list only if the C# language version is 10.0 or newer. |
| 77 | +
|
| 78 | + Also avoid trying to add Elskom.Generic.Libs twice when RootNamespace is that value. |
| 79 | + --> |
| 80 | + <Using Include="$(RootNamespace)" Condition="'$(ImplicitUsings)' == 'enable' AND '$(RootNamespace)' != 'Elskom.Generic.Libs'" /> |
| 81 | + <CompilerVisibleProperty Include="RootNamespace" /> |
| 82 | + <CompilerVisibleProperty Include="GitBuildInfoAssemblyType" /> |
| 83 | + <CompilerVisibleProperty Include="GitBuildInfoIsGeneric" /> |
| 84 | + <AdditionalFiles Include="$(IntermediateOutputPath)\git_head.txt" /> |
| 85 | + <AdditionalFiles Include="$(IntermediateOutputPath)\git_commit_hash.txt" /> |
| 86 | + <AdditionalFiles Include="$(IntermediateOutputPath)\git_branch.txt" /> |
| 87 | + </ItemGroup> |
| 88 | + |
| 89 | +</Project> |
0 commit comments