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

Invoke GetBuildVersion MSBuild task only once per project (or per repo) #508

Merged
merged 1 commit into from
Sep 4, 2020

Conversation

AArnott
Copy link
Collaborator

@AArnott AArnott commented Sep 4, 2020

A multi-targeting project will execute the GetBuildVersion target for every target framework, yet the result will never vary across those target frameworks. Since the GetBuildVersion 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 property GitVersionBaseDirectory 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:

<Project>
  <PropertyGroup>
    <GitVersionBaseDirectory>$(MSBuildThisFileDirectory)</GitVersionBaseDirectory>
  </PropertyGroup>
</Project>

@AArnott AArnott added this to the v3.3 milestone Sep 4, 2020
@AArnott AArnott self-assigned this Sep 4, 2020
@AArnott AArnott mentioned this pull request Sep 4, 2020
6 tasks
…epo)

A multi-targeting project will execute the `GetBuildVersion` target for every target framework, yet the result will never vary across those target frameworks. Since the `GetBuildVersion` 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.

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 property `GitVersionBaseDirectory` as `$(MSBuildThisFileDirectory)`, at which point all projects under that directory will reuse the result of the version calculation from just that one directory.
@AArnott AArnott added the auto-merge Auto-completes a PR when reviews and checks pass label Sep 4, 2020
@AArnott AArnott merged commit 4f10374 into master Sep 4, 2020
@AArnott AArnott deleted the perfImprovements branch September 4, 2020 23:27
@AArnott AArnott mentioned this pull request Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-merge Auto-completes a PR when reviews and checks pass enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant