This repository has been archived by the owner on May 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathKoreBuild.SolutionBuild.targets
355 lines (291 loc) · 14.6 KB
/
KoreBuild.SolutionBuild.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<!--
FYI: targets, properties, and items that begin with an underscore are meant to be internal.
They are subject to change. Overriding these may break these targets.
-->
<Project>
<!-- packages required to implement the targets in this file-->
<ItemGroup>
<PackageReference Include="NuGetPackageVerifier" Version="2.0.0-*"/>
</ItemGroup>
<PropertyGroup>
<PrepareDependsOn>$(PrepareDependsOn);CleanArtifacts;CleanSolutions;_PrepareOutputPaths;ResolveGitInfo</PrepareDependsOn>
<CompileDependsOn>$(CompileDependsOn);_CreateCommitHashArtifact;BuildSolutions</CompileDependsOn>
<PackageDependsOn>$(PackageDependsOn);PackageProjects;PackSharedSources</PackageDependsOn>
<TestDependsOn>$(TestDependsOn);TestProjects</TestDependsOn>
<VerifyDependsOn>$(VerifyDependsOn);VerifyPackages</VerifyDependsOn>
<CleanDependsOn>$(CleanDependsOn);CleanArtifacts;CleanSolutions</CleanDependsOn>
<RebuildDependsOn>$(RebuildDependsOn);RebuildSolutions</RebuildDependsOn>
</PropertyGroup>
<!--
###################################################################
Convenience targets.
These are not part of the standard lifecycle but are useful
###################################################################
-->
<Target Name="Resx" DependsOnTargets="_ResolveSolutions">
<Warning Text="No solutions found to build in '$(RepositoryRoot)'" Condition="'@(_SolutionItems)' == ''" />
<PropertyGroup>
<_ResxTargets>$(MSBuildThisFileDirectory)Project.CSharp.Resx.targets</_ResxTargets>
<_ResxSlnProps>$(_SolutionProperties)</_ResxSlnProps>
<!-- See comments in Project.CSharp.Resx.targets for what this does-->
<_ResxSlnProps>$(_ResxSlnProps);CustomAfterMicrosoftCommonTargets=$(_ResxTargets)</_ResxSlnProps>
<_ResxSlnProps>$(_ResxSlnProps);CustomAfterMicrosoftCommonCrossTargetingTargets=$(_ResxTargets)</_ResxSlnProps>
</PropertyGroup>
<MSBuild Targets="_GenerateResx"
Projects="@(_SolutionItems)"
Properties="$(_ResxSlnProps)"
BuildInParallel="$(BuildInParallel)"
Condition="'@(_SolutionItems)' != ''"
RemoveProperties="$(_BuildPropertiesToRemove)" />
</Target>
<!--
###################################################################
Individual build steps.
Repos that customize the build should not rely on these existing
as they are subject to change.
###################################################################
-->
<Target Name="CleanArtifacts">
<ItemGroup>
<_FilesToDelete Include="$(ArtifactsDir)**\*" Exclude="$(ArtifactsDir)msbuild\**\*" />
</ItemGroup>
<Delete Files="@(_FilesToDelete)" />
</Target>
<Target Name="_PrepareOutputPaths">
<MakeDir Directories="$(ArtifactsDir);$(BuildDir)" />
</Target>
<Target Name="ResolveGitInfo" Condition="'$(CommitHash)' == ''">
<PropertyGroup>
<CommitHash Condition="'$(APPVEYOR_REPO_COMMIT)' != ''">$(APPVEYOR_REPO_COMMIT)</CommitHash>
<GitBranch Condition="'$(APPVEYOR_REPO_BRANCH)' != ''">$(APPVEYOR_REPO_BRANCH)</GitBranch>
<CommitHash Condition="'$(TRAVIS_COMMIT)' != ''">$(TRAVIS_COMMIT)</CommitHash>
<GitBranch Condition="'$(TRAVIS_BRANCH)' != ''">$(TRAVIS_BRANCH)</GitBranch>
</PropertyGroup>
<GetGitCommitInfo WorkingDirectory="$(RepositoryRoot)"
Condition="'$(CommitHash)' == ''"
ContinueOnError="WarnAndContinue">
<Output TaskParameter="CommitHash" PropertyName="CommitHash" />
<Output TaskParameter="Branch" PropertyName="GitBranch" />
</GetGitCommitInfo>
</Target>
<!-- The filename that will contain the commit hash -->
<PropertyGroup>
<_CommitArtifactFileName>commit</_CommitArtifactFileName>
</PropertyGroup>
<Target Name="_CreateCommitHashArtifact" DependsOnTargets="_PrepareOutputPaths;ResolveGitInfo">
<WriteLinesToFile
File="$(ArtifactsDir)$(_CommitArtifactFileName)"
Overwrite="true"
Lines="$(CommitHash)"
Condition="'$(CommitHash)' != ''" />
</Target>
<!--
###################################################################
Targets: _UseVolatileFeed
Replaces $(RepositoryRoot)\NuGet.config feeds.
###################################################################
-->
<ItemGroup>
<_UpdateFeeds Include="ARTIFACTS" Value="$(NUGET_VOLATILE_FEED_ARTIFACTS)" Condition="'$(NUGET_VOLATILE_FEED_ARTIFACTS)' != ''" />
<_UpdateFeeds Include="AspNetCore" Value="$(NUGET_VOLATILE_FEED_AspNetCore)" Condition="'$(NUGET_VOLATILE_FEED_AspNetCore)' != ''" />
</ItemGroup>
<Target Name="_UseVolatileFeed" BeforeTargets="Restore" Condition="'@(_UpdateFeeds)' != '' AND '$(PreflightRestore)' != 'true'">
<UpdatePackageSource NuGetConfigPath="$(RepositoryRoot)NuGet.config"
SourceName="%(_UpdateFeeds.Identity)"
SourceUri="%(_UpdateFeeds.Value)"
Condition="'%(_UpdateFeeds.Value)' != ''" />
</Target>
<!--
###################################################################
Targets: {Target}Solutions
Items: Solutions
Properties: ExcludeSolutions
Executes /t:{Target} on all solutions
###################################################################
-->
<PropertyGroup>
<_SolutionWasBuilt>false</_SolutionWasBuilt>
<!-- ensure its value doesn't invalidate MSBuild build cache -->
<_BuildPropertiesToRemove>$(_BuildPropertiesToRemove);_SolutionWasBuilt</_BuildPropertiesToRemove>
<BuildInParallel>true</BuildInParallel>
</PropertyGroup>
<Target Name="_ResolveSolutions"
DependsOnTargets="ResolveGitInfo"
Returns="@(_SolutionItems)">
<RemoveDuplicates Inputs="@(Solutions)">
<Output TaskParameter="Filtered" ItemName="_SolutionItems" />
</RemoveDuplicates>
<PropertyGroup>
<_SolutionProperties>$(_SolutionProperties);Configuration=$(Configuration)</_SolutionProperties>
<_SolutionProperties Condition="'$(BuildNumber)' != ''">$(_SolutionProperties);BuildNumber=$(BuildNumber)</_SolutionProperties>
<_SolutionProperties Condition="'$(CommitHash)' != ''">$(_SolutionProperties);CommitHash=$(CommitHash)</_SolutionProperties>
<_SolutionProperties Condition="'$(GitBranch)' != ''">$(_SolutionProperties);GitBranch=$(GitBranch)</_SolutionProperties>
</PropertyGroup>
</Target>
<Target Name="CleanSolutions" DependsOnTargets="_ResolveSolutions">
<Error Text="No solutions found to build in '$(RepositoryRoot)'" Condition="'@(_SolutionItems)' == ''" />
<!--
Added _SolutionTarget to invalidate subsequent MSBuild calls on the solution.
MSBuild incorrectly caches the "Clean" target.
-->
<MSBuild Targets="Clean"
Projects="@(_SolutionItems)"
Properties="$(_SolutionProperties);_SolutionTarget=Clean"
RemoveProperties="$(_BuildPropertiesToRemove)" />
</Target>
<Target Name="BuildSolutions" DependsOnTargets="_ResolveSolutions">
<Error Text="No solutions found to build in '$(RepositoryRoot)'" Condition="'@(_SolutionItems)' == ''" />
<MSBuild Targets="Build"
Projects="@(_SolutionItems)"
Properties="$(_SolutionProperties)"
BuildInParallel="$(BuildInParallel)"
RemoveProperties="$(_BuildPropertiesToRemove)" />
<PropertyGroup>
<_SolutionWasBuilt>true</_SolutionWasBuilt>
</PropertyGroup>
</Target>
<Target Name="RebuildSolutions" DependsOnTargets="_ResolveSolutions">
<Error Text="No solutions found to build in '$(RepositoryRoot)'" Condition="'@(_SolutionItems)' == ''" />
<MSBuild Targets="Rebuild"
Projects="@(_SolutionItems)"
Properties="$(_SolutionProperties)"
RemoveProperties="$(_BuildPropertiesToRemove)" />
<PropertyGroup>
<_SolutionWasBuilt>true</_SolutionWasBuilt>
</PropertyGroup>
</Target>
<!--
###################################################################
Target: _GetRestoreItemsForSolutions
Extend the main restore entry point to include all projects from
solutions as well as the current file
###################################################################
-->
<Target Name="_GetRestoreItemsForSolutions"
DependsOnTargets="_ResolveSolutions;_InnerGetRestoreItemsForSolutions"
BeforeTargets="_LoadRestoreGraphEntryPoints"
Condition=" '$(PreflightRestore)' != 'true' " />
<!-- _GetRestoreItemsForSolutions ensures @(_SolutionItems) has been set up. -->
<Target Name="_InnerGetRestoreItemsForSolutions" Condition=" '@(_SolutionItems)' != '' ">
<ItemGroup>
<RestoreGraphProjectInputItems Include="$(RestoreGraphProjectInput)" />
</ItemGroup>
<!-- See https://github.com/NuGet/NuGet.Client/blob/0c21be9bad12327e929365bf76808274d4c6fe08/src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets#L139 -->
<MSBuild Targets="_LoadRestoreGraphEntryPoints"
Projects="@(_SolutionItems)"
Properties="$(_SolutionProperties)"
RemoveProperties="$(_BuildPropertiesToRemove)" >
<Output
TaskParameter="TargetOutputs"
ItemName="RestoreGraphProjectInputItems" />
</MSBuild>
<ItemGroup>
<!-- Ensure subsequent calls to MSBuild include essential properties, like BuildNumber. -->
<RestoreGraphProjectInputItems Update="@(RestoreGraphProjectInputItems)">
<AdditionalProperties>%(RestoreGraphProjectInputItems.AdditionalProperties);$(_SolutionProperties)</AdditionalProperties>
</RestoreGraphProjectInputItems>
</ItemGroup>
</Target>
<!--
###################################################################
Target: PackageProjects
Executes /t:Pack on all projects matching src/*/*.csproj.
###################################################################
-->
<Target Name="PackageProjects" DependsOnTargets="_ResolveSolutions">
<RemoveDuplicates Inputs="@(ProjectsToPack)">
<Output TaskParameter="Filtered" ItemName="_PackProjectItems" />
</RemoveDuplicates>
<PropertyGroup>
<PackageNoBuild Condition="'$(PackageNoBuild)' == ''">$(_SolutionWasBuilt)</PackageNoBuild>
</PropertyGroup>
<MSBuild Targets="Pack"
Projects="@(_PackProjectItems)"
Condition="'@(_PackProjectItems)' != ''"
Properties="$(_SolutionProperties);PackageOutputPath=$(BuildDir);NoBuild=$(PackageNoBuild)"
BuildInParallel="$(BuildInParallel)"
RemoveProperties="$(_BuildPropertiesToRemove);PackageNoBuild" />
</Target>
<!--
###################################################################
Target: PackSharedSources
Creates a content files package for all each directory in
that matches "$(RepositoryRoot)/shared/*.Sources".
###################################################################
-->
<Target Name="PackSharedSources" Condition="Exists('$(SharedSourcesFolder)') OR '@(SharedSourceDirectories)' != ''">
<RemoveDuplicates Inputs="@(SharedSourceDirectories)">
<Output TaskParameter="Filtered" ItemName="_SharedSourceItems" />
</RemoveDuplicates>
<Message Importance="normal"
Text="Producing shared source package for %(_SharedSourceItems.Identity)"
Condition="'@(_SharedSourceItems)' != ''" />
<MSBuild Targets="Pack"
Projects="$(MSBuildThisFileDirectory)..\shared\sharedsources.csproj"
Properties="PackageOutputPath=$(BuildDir);RepositoryRoot=$(RepositoryRoot);NuspecBasePath=%(_SharedSourceItems.Identity);PackageId=%(FileName)%(Extension);BuildNumber=$(BuildNumber)"
Condition="'@(_SharedSourceItems)' != ''"
BuildInParallel="$(BuildInParallel)" />
</Target>
<!--
###################################################################
Target: TestProjects
Items: ProjectsToTest. Defaults to test/*/*.csproj
Properties: ExcludeFromTest. ItemSpec for projects to avoid testing.
Runs the VSTest on all projects in the ProjectsToTest itemgroup.
###################################################################
-->
<PropertyGroup>
<VSTestLogger Condition=" '$(VSTestLogger)' == '' AND '$(TEAMCITY_VERSION)' != '' ">trx</VSTestLogger>
<VSTestAutoReporters Condition=" '$(VSTestAutoReporters)' == '' AND '$(VSTestLogger)' != '' ">false</VSTestAutoReporters>
<VSTestAutoReporters Condition=" '$(VSTestAutoReporters)' == '' ">true</VSTestAutoReporters>
<IgnoreFailingTestProjects>false</IgnoreFailingTestProjects>
<IgnoreFailingTestProjects Condition="'$(KOREBUILD_IGNORE_DOTNET_TEST_EXIT_CODE)' == '1'">true</IgnoreFailingTestProjects>
</PropertyGroup>
<Target Name="TestProjects" DependsOnTargets="_ResolveSolutions">
<RemoveDuplicates Inputs="@(ProjectsToTest)">
<Output TaskParameter="Filtered" ItemName="_TestProjectItems" />
</RemoveDuplicates>
<Message Text="%0ARunning tests for:%0A@(_TestProjectItems -> '%(FileName)','%0A')%0A"
Importance="High"
Condition="'@(_TestProjectItems)' != ''" />
<PropertyGroup>
<!--
Disable other test reporters if trx logging is enabled.
VSTestCLIRunSettings is a space-separated list of key=value pairs.
-->
<VSTestCLIRunSettings Condition=" '$(VSTestAutoReporters)' != 'true' ">RunConfiguration.NoAutoReporters=true $(VSTestCLIRunSettings)</VSTestCLIRunSettings>
<VSTestNoBuild Condition="'$(VSTestNoBuild)' == ''">$(_SolutionWasBuilt)</VSTestNoBuild>
<_TestContinueOnError Condition="'$(IgnoreFailingTestProjects)' == 'true'">ErrorAndContinue</_TestContinueOnError>
<_TestContinueOnError Condition="'$(IgnoreFailingTestProjects)' != 'true'">ErrorAndStop</_TestContinueOnError>
</PropertyGroup>
<!-- Intentional use of batching ('%') instead of passing items ('@') so that tests fail sooner -->
<MSBuild Projects="%(_TestProjectItems.Identity)"
Targets="VSTest"
Properties="$(_SolutionProperties);VSTestLogger=$(VSTestLogger);VSTestNoBuild=$(VSTestNoBuild);VSTestCLIRunSettings=$([MSBuild]::Escape('$(VSTestCLIRunSettings)'));%(_TestProjectItems.AdditionalProperties)"
Condition="'@(_TestProjectItems)' != ''"
ContinueOnError="$(_TestContinueOnError)"
RemoveProperties="$(_BuildPropertiesToRemove)" />
</Target>
<!--
###################################################################
Target: VerifyPackages
Runs the NuGet Package Verifier on all nupkgs in build output.
Only runs if a file named NuGetPackageVerifier.json is in the
repository root.
###################################################################
-->
<PropertyGroup>
<NuGetVerifierRuleFile>$(RepositoryRoot)NuGetPackageVerifier.json</NuGetVerifierRuleFile>
</PropertyGroup>
<Target Name="VerifyPackages" Condition="Exists('$(NuGetVerifierRuleFile)')">
<ItemGroup>
<Packages Include="$(BuildDir)*.nupkg" />
</ItemGroup>
<Warning Text="No nupkg found in '$(BuildDir)'." Condition="$(Packages -> Count()) == 0" />
<Warning Text="Skipping nuget package verification because artifacts directory could not be found"
Condition="!Exists('$(BuildDir)')" />
<VerifyPackages ArtifactDirectory="$(BuildDir)"
RuleFile="$(NuGetVerifierRuleFile)"
Condition="Exists('$(BuildDir)')" />
</Target>
</Project>