-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Invoke
GetBuildVersion
MSBuild task only once per project (or per r…
…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.
- Loading branch information
Showing
8 changed files
with
208 additions
and
54 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/Nerdbank.GitVersioning.Tasks/build/Nerdbank.GitVersioning.Common.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<_NBGV_PlatformSuffix Condition=" '$(_NBGV_PlatformSuffix)' == '' and '$(MSBuildRuntimeType)' == 'Core' ">MSBuildCore/</_NBGV_PlatformSuffix> | ||
<_NBGV_PlatformSuffix Condition=" '$(_NBGV_PlatformSuffix)' == '' ">MSBuildFull/</_NBGV_PlatformSuffix> | ||
<NerdbankGitVersioningTasksPath Condition=" '$(NerdbankGitVersioningTasksPath)' == '' ">$(MSBuildThisFileDirectory)$(_NBGV_PlatformSuffix)</NerdbankGitVersioningTasksPath> | ||
</PropertyGroup> | ||
</Project> |
45 changes: 45 additions & 0 deletions
45
src/Nerdbank.GitVersioning.Tasks/build/Nerdbank.GitVersioning.Inner.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<Import Project="Nerdbank.GitVersioning.Common.targets"/> | ||
|
||
<UsingTask AssemblyFile="$(NerdbankGitVersioningTasksPath)Nerdbank.GitVersioning.Tasks.dll" TaskName="Nerdbank.GitVersioning.Tasks.GetBuildVersion"/> | ||
|
||
<Target Name="GetBuildVersion_Properties" | ||
DependsOnTargets="GetBuildVersionCore" | ||
Returns="@(NBGV_PropertyItems)" /> | ||
|
||
<Target Name="GetBuildVersion_CloudBuildVersionVars" | ||
DependsOnTargets="GetBuildVersionCore" | ||
Returns="@(CloudBuildVersionVars)" /> | ||
|
||
<Target Name="GetBuildVersionCore"> | ||
<Nerdbank.GitVersioning.Tasks.GetBuildVersion | ||
BuildingRef="$(_NBGV_BuildingRef)" | ||
BuildMetadata="$(BuildMetadata.Replace(',',';'))" | ||
DefaultPublicRelease="$(PublicRelease)" | ||
ProjectDirectory="$(ProjectDirectory)" | ||
GitRepoRoot="$(GitRepoRoot)" | ||
ProjectPathRelativeToGitRepoRoot="$(ProjectPathRelativeToGitRepoRoot)" | ||
OverrideBuildNumberOffset="$(OverrideBuildNumberOffset)" | ||
TargetsPath="$(MSBuildThisFileDirectory)"> | ||
|
||
<!-- All properties and items are to be exported to the calling project through items. --> | ||
<Output TaskParameter="OutputProperties" ItemName="NBGV_PropertyItems"/> | ||
<Output TaskParameter="CloudBuildVersionVars" ItemName="CloudBuildVersionVars" /> | ||
|
||
<!-- Export a couple of properties directly to support our tasks below. --> | ||
<Output TaskParameter="AssemblyInformationalVersion" PropertyName="AssemblyInformationalVersion" /> | ||
<Output TaskParameter="NuGetPackageVersion" PropertyName="NuGetPackageVersion" /> | ||
<Output TaskParameter="Version" PropertyName="BuildVersion" /> | ||
<Output TaskParameter="GitCommitId" PropertyName="GitCommitId" /> | ||
</Nerdbank.GitVersioning.Tasks.GetBuildVersion> | ||
|
||
<Warning Condition=" '$(AssemblyInformationalVersion)' == '' " Text="Unable to determine the git HEAD commit ID to use for informational version number." /> | ||
<Message Condition=" '$(AssemblyInformationalVersion)' != '' " Text="Building version $(BuildVersion) from commit $(GitCommitId)"/> | ||
<Message Condition=" '$(AssemblyInformationalVersion)' == '' " Text="Building version $(BuildVersion)"/> | ||
<Message Importance="low" Text="AssemblyInformationalVersion: $(AssemblyInformationalVersion)" /> | ||
<Message Importance="low" Text="NuGetPackageVersion: $(NuGetPackageVersion)" /> | ||
</Target> | ||
|
||
</Project> |
Oops, something went wrong.