|
62 | 62 | <!-- Consider building a tag to be more precise than the branch we're building. --> |
63 | 63 | <_NBGV_BuildingRef>$(_NBGV_BuildingTag)</_NBGV_BuildingRef> |
64 | 64 | <_NBGV_BuildingRef Condition=" '$(_NBGV_BuildingRef)' == '' ">$(_NBGV_BuildingBranch)</_NBGV_BuildingRef> |
| 65 | + |
| 66 | + <GitVersionBaseDirectory Condition=" '$(GitVersionBaseDirectory)' == '' ">$(MSBuildProjectDirectory)</GitVersionBaseDirectory> |
| 67 | + <NBGV_InnerGlobalProperties Condition=" '$(GitRepoRoot)' != '' ">$(NBGV_InnerGlobalProperties)GitRepoRoot=$(GitRepoRoot);</NBGV_InnerGlobalProperties> |
| 68 | + <NBGV_InnerGlobalProperties Condition=" '$(PublicRelease)' != '' ">$(NBGV_InnerGlobalProperties)PublicRelease=$(PublicRelease);</NBGV_InnerGlobalProperties> |
| 69 | + <NBGV_InnerGlobalProperties Condition=" '$(_NBGV_BuildingRef)' != '' ">$(NBGV_InnerGlobalProperties)_NBGV_BuildingRef=$(_NBGV_BuildingRef);</NBGV_InnerGlobalProperties> |
| 70 | + <NBGV_InnerGlobalProperties Condition=" '$(ProjectPathRelativeToGitRepoRoot)' != '' ">$(NBGV_InnerGlobalProperties)ProjectPathRelativeToGitRepoRoot=$(ProjectPathRelativeToGitRepoRoot);</NBGV_InnerGlobalProperties> |
| 71 | + <NBGV_InnerGlobalProperties Condition=" '$(GitVersionBaseDirectory)' != '' ">$(NBGV_InnerGlobalProperties)ProjectDirectory=$(GitVersionBaseDirectory);</NBGV_InnerGlobalProperties> |
| 72 | + <NBGV_InnerGlobalProperties Condition=" '$(OverrideBuildNumberOffset)' != '' ">$(NBGV_InnerGlobalProperties)OverrideBuildNumberOffset=$(OverrideBuildNumberOffset);</NBGV_InnerGlobalProperties> |
| 73 | + <NBGV_CoreTargets>$(MSBuildThisFileDirectory)Nerdbank.GitVersioning.Inner.targets</NBGV_CoreTargets> |
65 | 74 | </PropertyGroup> |
66 | 75 |
|
67 | | - <Target Name="GetBuildVersion" Returns="$(BuildVersion)"> |
68 | | - <PropertyGroup> |
69 | | - <GitVersionBaseDirectory Condition=" '$(GitVersionBaseDirectory)' == '' ">$(MSBuildProjectDirectory)</GitVersionBaseDirectory> |
70 | | - <NBGV_InnerGlobalProperties> |
71 | | - GitRepoRoot=$(GitRepoRoot); |
72 | | - PublicRelease=$(PublicRelease); |
73 | | - BuildMetadata=@(BuildMetadata, ','); |
74 | | - _NBGV_BuildingRef=$(_NBGV_BuildingRef); |
75 | | - ProjectPathRelativeToGitRepoRoot=$(ProjectPathRelativeToGitRepoRoot); |
76 | | - ProjectDirectory=$(GitVersionBaseDirectory); |
77 | | - OverrideBuildNumberOffset=$(OverrideBuildNumberOffset); |
78 | | - </NBGV_InnerGlobalProperties> |
79 | | - <NBGV_CoreTargets>$(MSBuildThisFileDirectory)Nerdbank.GitVersioning.Inner.targets</NBGV_CoreTargets> |
80 | | - </PropertyGroup> |
| 76 | + <!-- Compile a list of global properties that may vary when a project builds but that would never influence the result of the GetBuildVersion task. --> |
| 77 | + <ItemGroup> |
| 78 | + <NBGV_GlobalPropertiesToRemove Include="TargetFramework" /> |
| 79 | + <NBGV_GlobalPropertiesToRemove Include="RuntimeIdentifier" /> |
| 80 | + <NBGV_GlobalPropertiesToRemove Include="Configuration" /> |
| 81 | + <NBGV_GlobalPropertiesToRemove Include="Platform" /> |
| 82 | + |
| 83 | + <_BuildMetadataSnapped Include="@(BuildMetadata)" /> |
| 84 | + </ItemGroup> |
81 | 85 |
|
82 | | - <!-- Compile a list of global properties that may vary when a project builds but that would never influence the result of the GetBuildVersion task. --> |
83 | | - <ItemGroup> |
84 | | - <NBGV_GlobalPropertiesToRemove Include="TargetFramework" /> |
85 | | - </ItemGroup> |
| 86 | + <ItemGroup> |
| 87 | + <!-- Declare a P2P so that "msbuild -graph -isolate" doesn't complain when we use the MSBuild task to invoke our inner shared project. --> |
| 88 | + <ProjectReference Include="$(NBGV_CoreTargets)"> |
| 89 | + <Targets>GetBuildVersion_Properties;GetBuildVersion_CloudBuildVersionVars</Targets> |
| 90 | + <Properties>$(NBGV_InnerGlobalProperties)BuildMetadata=@(BuildMetadata, ',');</Properties> |
| 91 | + <GlobalPropertiesToRemove>@(NBGV_GlobalPropertiesToRemove)</GlobalPropertiesToRemove> |
86 | 92 |
|
| 93 | + <!-- 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. --> |
| 94 | + <BuildReference>false</BuildReference> |
| 95 | + <ReferenceOutputAssembly>false</ReferenceOutputAssembly> |
| 96 | + <SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties> |
| 97 | + <Visible>false</Visible> |
| 98 | + <NBGV_InnerProject>true</NBGV_InnerProject> |
| 99 | + </ProjectReference> |
| 100 | + </ItemGroup> |
| 101 | + |
| 102 | + <Target Name="GetBuildVersion" Returns="$(BuildVersion)"> |
| 103 | + <Error Text="BuildMetadata items changed after a copy was made. Add all BuildMetadata items before importing this file." Condition=" '@(BuildMetadata)' != '@(_BuildMetadataSnapped)' " /> |
| 104 | + |
87 | 105 | <!-- Calculate version by invoking another "project" with global properties that will serve as a key |
88 | 106 | into an msbuild cache to ensure we only invoke the GetBuildVersion task as many times as will produce a unique value. --> |
89 | | - <MSBuild Projects="$(NBGV_CoreTargets)" Properties="$(NBGV_InnerGlobalProperties)" RemoveProperties="@(NBGV_GlobalPropertiesToRemove)" Targets="GetBuildVersion_Properties"> |
| 107 | + <MSBuild Projects="@(ProjectReference)" |
| 108 | + Condition=" '%(ProjectReference.NBGV_InnerProject)' == 'true' " |
| 109 | + Properties="%(ProjectReference.Properties)" |
| 110 | + RemoveProperties="%(ProjectReference.GlobalPropertiesToRemove)" |
| 111 | + Targets="GetBuildVersion_Properties"> |
90 | 112 | <Output TaskParameter="TargetOutputs" ItemName="NBGV_PropertyItems" /> |
91 | 113 | </MSBuild> |
92 | 114 |
|
|
103 | 125 | </PropertyGroup> |
104 | 126 |
|
105 | 127 | <!-- Also get other items. --> |
106 | | - <MSBuild Projects="$(NBGV_CoreTargets)" Properties="$(NBGV_InnerGlobalProperties)" RemoveProperties="@(NBGV_GlobalPropertiesToRemove)" Targets="GetBuildVersion_CloudBuildVersionVars"> |
| 128 | + <MSBuild Projects="@(ProjectReference)" |
| 129 | + Condition=" '%(ProjectReference.NBGV_InnerProject)' == 'true' " |
| 130 | + Properties="%(ProjectReference.Properties)" |
| 131 | + RemoveProperties="%(ProjectReference.GlobalPropertiesToRemove)" |
| 132 | + Targets="GetBuildVersion_CloudBuildVersionVars"> |
107 | 133 | <Output TaskParameter="TargetOutputs" ItemName="CloudBuildVersionVars" /> |
108 | 134 | </MSBuild> |
109 | 135 | </Target> |
|
0 commit comments