Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly detect HEAD changes for incremental builds #226

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ Available [MSBuild properties](https://learn.microsoft.com/en-us/visualstudio/ms
performance reasons.
Defaults to empty value (no ignoring).

$(GitCachePath): where to cache the determined Git information
gives the chance to use a shared location
for different projects. this can improve
the overall build time.
has to end with a path seperator
Defaults to empty value ('$(IntermediateOutputPath)').

$(GitNameRevOptions): Options passed to git name-rev when finding
a branch name for the current commit (Detached head). The default is
'--refs=refs/heads/* --no-undefined --alwas'
Expand Down
21 changes: 21 additions & 0 deletions src/GitInfo/build/GitInfo.targets
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,27 @@

</Target>

<!-- This combination of prop/item/target fix incremental builds after HEAD changes. -->
<PropertyGroup>
<_GitCacheFullPath>$([System.IO.Path]::Combine($(MSBuildProjectDirectory), $(GitCachePath)))</_GitCacheFullPath>
<!-- We read the path to the HEAD file, written in a previously run _GitWriteHeadPath target -->
<_GitHeadPath Condition="Exists('$(_GitCacheFullPath)GitHead.cache')">$([System.IO.File]::ReadAllText('$(_GitCacheFullPath)GitHead.cache').Trim())</_GitHeadPath>
</PropertyGroup>

<ItemGroup>
<!-- And if the HEAD path exists, we add it as an input for the fast up-to-date check VS performs -->
<UpToDateCheckInput Condition="'$(_GitHeadPath)' != '' and Exists('$(_GitHeadPath)')" Include="$(_GitHeadPath)" />
</ItemGroup>

<!-- NOTE: we write the path to HEAD after first calculating a version, since we can be anywhere in
the solution structure. This file will only be written if there's a change in the git root,
which should never happen. -->
<Target Name="_GitWriteHeadPath" AfterTargets="GitVersion">
<WriteLinesToFile Lines="$(GitRoot).git\HEAD"
File="$(GitCachePath)GitHead.cache"
Overwrite="true" WriteOnlyWhenDifferent="true" />
</Target>

<!--
============================================================
GitExe Property
Expand Down