|
55 | 55 | </PackageReference>
|
56 | 56 | </ItemGroup>
|
57 | 57 |
|
58 |
| - <!-- This is to add the CommitDate and CommitHash to your assemblyinfo --> |
59 |
| - |
| 58 | + <!-- Add git commit date to assembly metadata --> |
60 | 59 | <PropertyGroup>
|
61 | 60 | <GitCheckCommand>git rev-parse --is-inside-work-tree</GitCheckCommand>
|
62 |
| - <GitLogCommand>git log -1 --format=%%ct</GitLogCommand> |
| 61 | + <GitLogCommand>git log -1 --format=%%cI</GitLogCommand> |
63 | 62 | </PropertyGroup>
|
64 | 63 |
|
65 | 64 | <Target Name="SetAssemblyMetaData" BeforeTargets="PreBuildEvent">
|
66 |
| - <!-- Check if inside a Git repository and suppress output --> |
| 65 | + <!-- Check if inside a Git repository --> |
67 | 66 | <Exec Command="$(GitCheckCommand)" IgnoreExitCode="true" StandardOutputImportance="Low" StandardErrorImportance="Low">
|
68 | 67 | <Output TaskParameter="ExitCode" PropertyName="GitInRepo" />
|
69 | 68 | </Exec>
|
|
74 | 73 | <GitRepoAvailable>false</GitRepoAvailable>
|
75 | 74 | </PropertyGroup>
|
76 | 75 |
|
77 |
| - <!-- Get the latest commit timestamp if inside a Git repository --> |
| 76 | + <!-- Get formatted commit date directly from git --> |
78 | 77 | <Exec Command="$(GitLogCommand)" ConsoleToMSBuild="true" Condition="'$(GitRepoAvailable)' == 'true'" StandardOutputImportance="Low" StandardErrorImportance="Low">
|
79 |
| - <Output TaskParameter="ConsoleOutput" PropertyName="GitCommitTimestamp"/> |
| 78 | + <Output TaskParameter="ConsoleOutput" PropertyName="LastCommitDate"/> |
80 | 79 | </Exec>
|
81 |
| - <!-- Windows: Use the working DateTime.Parse().AddSeconds() approach --> |
82 |
| - <PropertyGroup Condition="'$(GitRepoAvailable)' == 'true' AND '$(OS)' == 'Windows_NT'"> |
83 |
| - <!-- Define the Unix epoch start date --> |
84 |
| - <UnixEpochStart>1970-01-01T00:00:00Z</UnixEpochStart> |
85 |
| - <!-- Calculate the commit date in UTC from the timestamp --> |
86 |
| - <GitCommitDate>$([System.DateTime]::Parse($(UnixEpochStart)).AddSeconds($(GitCommitTimestamp)).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssK'))</GitCommitDate> |
87 |
| - <!-- Assign the calculated date to LastCommitDate --> |
88 |
| - <LastCommitDate>$(GitCommitDate)</LastCommitDate> |
89 |
| - </PropertyGroup> |
90 |
| - |
91 |
| - <!-- Linux/macOS: Use DateTime.Now as workaround (MSBuild limitation) --> |
92 |
| - <PropertyGroup Condition="'$(GitRepoAvailable)' == 'true' AND '$(OS)' != 'Windows_NT'"> |
93 |
| - <!-- LIMITATION: DateTime.Parse().AddSeconds() fails on Linux with "Method not found" |
94 |
| - This is a known MSBuild cross-platform limitation. Using DateTime.Now as fallback. |
95 |
| - Git commit timestamp $(GitCommitTimestamp) is available but cannot be converted. --> |
96 |
| - <LastCommitDate>$([System.DateTime]::Now.ToString('yyyy-MM-ddTHH:mm:ssK'))</LastCommitDate> |
97 |
| - </PropertyGroup> |
98 | 80 | <ItemGroup Condition="'$(GitRepoAvailable)' == 'true'">
|
99 | 81 | <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
|
100 | 82 | <_Parameter1>CommitDate</_Parameter1>
|
|
0 commit comments