forked from dotnet/Nerdbank.GitVersioning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MSBuildTargetCaching.targets
61 lines (54 loc) · 4.14 KB
/
MSBuildTargetCaching.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<NBGV_InnerGlobalProperties Condition=" '$(GitRepoRoot)' != '' ">$(NBGV_InnerGlobalProperties)GitRepoRoot=$(GitRepoRoot);</NBGV_InnerGlobalProperties>
<NBGV_InnerGlobalProperties Condition=" '$(PublicRelease)' != '' ">$(NBGV_InnerGlobalProperties)PublicRelease=$(PublicRelease);</NBGV_InnerGlobalProperties>
<NBGV_InnerGlobalProperties Condition=" '$(_NBGV_BuildingRef)' != '' ">$(NBGV_InnerGlobalProperties)_NBGV_BuildingRef=$(_NBGV_BuildingRef);</NBGV_InnerGlobalProperties>
<NBGV_InnerGlobalProperties Condition=" '$(ProjectPathRelativeToGitRepoRoot)' != '' ">$(NBGV_InnerGlobalProperties)ProjectPathRelativeToGitRepoRoot=$(ProjectPathRelativeToGitRepoRoot);</NBGV_InnerGlobalProperties>
<NBGV_InnerGlobalProperties Condition=" '$(GitVersionBaseDirectory)' != '' ">$(NBGV_InnerGlobalProperties)GitVersionBaseDirectory=$(GitVersionBaseDirectory);</NBGV_InnerGlobalProperties>
<NBGV_InnerGlobalProperties Condition=" '$(OverrideBuildNumberOffset)' != '' ">$(NBGV_InnerGlobalProperties)OverrideBuildNumberOffset=$(OverrideBuildNumberOffset);</NBGV_InnerGlobalProperties>
<NBGV_InnerGlobalProperties Condition=" '$(NBGV_PrivateP2PAuxTargets)' != '' ">$(NBGV_InnerGlobalProperties)NBGV_PrivateP2PAuxTargets=$(NBGV_PrivateP2PAuxTargets);</NBGV_InnerGlobalProperties>
</PropertyGroup>
<!-- Compile a list of global properties that may vary when a project builds but that would never influence the result of the GetBuildVersion task. -->
<ItemGroup>
<NBGV_GlobalPropertiesToRemove Include="TargetFramework" />
<NBGV_GlobalPropertiesToRemove Include="RuntimeIdentifier" />
<_BuildMetadataSnapped Include="@(BuildMetadata)" />
</ItemGroup>
<ItemGroup>
<!-- Declare a P2P so that "msbuild -graph -isolate" doesn't complain when we use the MSBuild task to invoke our inner shared project. -->
<ProjectReference Include="$(NBGV_CachingProjectReference)">
<Targets>GetBuildVersion_Properties;GetBuildVersion_CloudBuildVersionVars</Targets>
<Properties>$(NBGV_InnerGlobalProperties)BuildMetadata=@(BuildMetadata, ',');</Properties>
<SetConfiguration>Configuration=Release</SetConfiguration>
<SetPlatform>Platform=AnyCPU</SetPlatform>
<GlobalPropertiesToRemove>@(NBGV_GlobalPropertiesToRemove)</GlobalPropertiesToRemove>
<!-- Do our very best to prevent Microsoft.Common.CurrentVersion.targets or IDEs from processing this P2P. It's only here for MSBuild's static graph. -->
<BuildReference>false</BuildReference>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
<Visible>false</Visible>
<NBGV_InnerProject>true</NBGV_InnerProject>
<PrivateAssets>all</PrivateAssets>
</ProjectReference>
</ItemGroup>
<Target Name="InvokeGetBuildVersionTask">
<Error Text="BuildMetadata items changed after a copy was made. Add all BuildMetadata items before importing this file." Condition=" '@(BuildMetadata)' != '@(_BuildMetadataSnapped)' " />
<!-- Calculate version by invoking another "project" with global properties that will serve as a key
into an msbuild cache to ensure we only invoke the GetBuildVersion task as many times as will produce a unique value. -->
<MSBuild Projects="@(ProjectReference)"
Condition=" '%(ProjectReference.NBGV_InnerProject)' == 'true' "
Properties="%(ProjectReference.Properties)"
RemoveProperties="%(ProjectReference.GlobalPropertiesToRemove)"
Targets="GetBuildVersion_Properties">
<Output TaskParameter="TargetOutputs" ItemName="NBGV_PropertyItems" />
</MSBuild>
<!-- Also get other items. -->
<MSBuild Projects="@(ProjectReference)"
Condition=" '%(ProjectReference.NBGV_InnerProject)' == 'true' "
Properties="%(ProjectReference.Properties)"
RemoveProperties="%(ProjectReference.GlobalPropertiesToRemove)"
Targets="GetBuildVersion_CloudBuildVersionVars">
<Output TaskParameter="TargetOutputs" ItemName="CloudBuildVersionVars" />
</MSBuild>
</Target>
</Project>