Invoke GetBuildVersion
MSBuild task only once per project (or per repo)
#508
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A multi-targeting project will execute the
GetBuildVersion
target for every target framework, yet the result will never vary across those target frameworks. Since theGetBuildVersion
task is costly to run, we can significantly reduce wasted build time in the multi-targeting scenario by invoking the task within a special project that never varies by TargetFramework and then communicating the result back to the calling project.This multi-targeting optimization is always on with no effort on the consumer's part.
In fact, because MSBuild will cache the results based on project file and global properties, we can even allow the repo to control the global properties such that they get exactly one
GetBuildVersion
invocation for the entire repo's build.In the most trivial case, a repo can define a
Directory.Build.props
file that defines the MSBuild propertyGitVersionBaseDirectory
as$(MSBuildThisFileDirectory)
, at which point all projects under that directory will reuse the result of the version calculation from just that one directory. Like this: