-
Notifications
You must be signed in to change notification settings - Fork 695
/
Directory.Solution.targets
287 lines (254 loc) · 13 KB
/
Directory.Solution.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
<!--
Specifies build logic when building a solution file.
-->
<Project>
<PropertyGroup>
<!--
Set some default property values unless otherwise specified.
-->
<VSTestNoLogo Condition="'$(VSTestNoLogo)' == ''">true</VSTestNoLogo>
<VSTestVerbosity Condition="'$(SYSTEM_DEBUG)' == 'true'">detailed</VSTestVerbosity>
<VSTestVerbosity Condition="'$(VSTestVerbosity)' == ''">quiet</VSTestVerbosity>
<VSTestSetting Condition="'$(VSTestSetting)' == ''">$([System.IO.Path]::Combine('$(MSBuildThisFileDirectory)', 'build', 'xunit.runsettings'))</VSTestSetting>
<VSTestResultsDirectory Condition="'$(VSTestResultsDirectory)' == ''">$([System.IO.Path]::Combine('$(MSBuildThisFileDirectory)', 'TestResults'))</VSTestResultsDirectory>
<!--
Build tests for all supported target frameworks by default, otherwise build tests for just the specified target framework.
-->
<BuildTestsDependsOn Condition="'$(TargetFramework)' == ''">BuildTestsForAllTargetFrameworks</BuildTestsDependsOn>
<BuildTestsDependsOn Condition="'$(TargetFramework)' != ''">BuildTestsForSingleTargetFramework</BuildTestsDependsOn>
<!--
If a user does not specify a target framework, run tests for all frameworks one-by-one, otherwise run tests for that framework only.
-->
<VSTestDependsOn Condition="'$(TargetFramework)' == ''">VSTestAllTargetFrameworks</VSTestDependsOn>
<VSTestDependsOn Condition="'$(TargetFramework)' != ''">VSTestSingleTargetFramework</VSTestDependsOn>
</PropertyGroup>
<!--
Defines a target which is run when a user executes 'dotnet test'. This target runs tests for all frameworks or a single target framework depending on whether or not the user specified the framework at the command-line.
-->
<Target Name="VSTest" DependsOnTargets="$(VSTestDependsOn)" />
<!--
Defines a target which builds only test projects when executing 'dotnet test'.
-->
<Target Name="BuildTests"
Condition="'$(VSTestNoBuild)' != 'true'"
DependsOnTargets="$(BuildTestsDependsOn)" />
<!--
Gets a list of all test projects in the solution and categorizes them by test type (Unit or Functional). By default, only the Unit test projects are returned. To get Functional test projects, set the TestType property to 'Functional' via -Property:TestType=Functional.
-->
<Target Name="GetTestProjects">
<PropertyGroup>
<TestType Condition="'$(TestType)' == ''">Unit</TestType>
</PropertyGroup>
<!--
Run the IsTestProject target on each project reference to determine what type of test project it is.
-->
<MSBuild Projects="@(ProjectReference)"
BuildInParallel="true"
Targets="IsTestProject"
RemoveProperties="TargetFramework">
<Output TaskParameter="TargetOutputs"
ItemName="_TestProject" />
</MSBuild>
<MSBuild Projects="@(_TestProject)"
Targets="DoesProjectSupportTargetFramework"
Condition="'$(TargetFramework)' != ''"
BuildInParallel="$(BuildInParallel)"
RemoveProperties="TargetFramework"
Properties="ProjectTargetFramework=$(TargetFramework)">
<Output TaskParameter="TargetOutputs"
ItemName="_TestProjectForFramework" />
</MSBuild>
<ItemGroup>
<!--
Add only the specified test type to the TestProject item group.
-->
<TestProject Include="@(_TestProject->WithMetadataValue('TestType', '$(TestType)'))" Condition="'$(TargetFramework)' == ''" />
<TestProject Include="@(_TestProjectForFramework->WithMetadataValue('TestType', '$(TestType)'))" Condition="'$(TargetFramework)' != ''" />
</ItemGroup>
<ItemGroup Condition="'$(TestProjectName)' != ''">
<_FilteredTestProject Include="@(TestProject)" Condition="'%(TestProject.ProjectName)' == '$(TestProjectName)'" />
</ItemGroup>
<Error Text="The specified test project '$(TestProjectName)' was not found. Possible projects are "@(TestProject->'%(ProjectName)', ', ')""
Condition="'$(TestProjectName)' != '' And @(_FilteredTestProject->Count()) == 0" />
<ItemGroup Condition="'$(TestProjectName)' != ''">
<TestProject Remove="@(TestProject)" />
<TestProject Include="@(_FilteredTestProject)" />
</ItemGroup>
<!--
Log an error if no test projects were found with the specified TestType.
-->
<Error Text="Invalid TestType value '$(TestType)'. Valid values are 'Unit', 'Functional'."
Condition="@(TestProject->Count()) == 0" />
</Target>
<!--
Builds all test projects in the solution for all target frameworks.
-->
<Target Name="BuildTestsForAllTargetFrameworks"
DependsOnTargets="GetTestProjects"
Condition="'$(VSTestNoBuild)' != 'true'">
<Message Text="Building test projects for all frameworks (specify --no-build to skip building projects)"
Importance="High" />
<MSBuild Projects="@(TestProject)"
BuildInParallel="true"
Targets="Build"
RemoveProperties="TargetFramework"
Properties="BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" />
</Target>
<!--
Builds test projects in the solution for a single target framework.
-->
<Target Name="BuildTestsForSingleTargetFramework"
DependsOnTargets="GetTestProjects"
Condition="'$(VSTestNoBuild)' != 'true'">
<Message Text="Building test projects for framework '$(TargetFramework)' (specify --no-build to skip building projects)"
Importance="High" />
<MSBuild Projects="@(TestProject)"
Targets="DoesProjectSupportTargetFramework"
BuildInParallel="$(BuildInParallel)"
RemoveProperties="TargetFramework"
Properties="ProjectTargetFramework=$(TargetFramework)">
<Output TaskParameter="TargetOutputs"
ItemName="TestProjectForFramework" />
</MSBuild>
<MSBuild Projects="@(TestProjectForFramework)"
BuildInParallel="true"
Targets="Build"
Properties="BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" />
</Target>
<!--
Gets a list of all supported target frameworks and schedule a test run for each framework.
-->
<Target Name="VSTestAllTargetFrameworks"
DependsOnTargets="GetTestProjects;BuildTests">
<!--
Gets a list of all supported target frameworks for each test project.
-->
<MSBuild Projects="@(TestProject)"
Targets="GetProjectTargetFrameworks"
BuildInParallel="$(BuildInParallel)"
RemoveProperties="TargetFramework">
<Output TaskParameter="TargetOutputs"
ItemName="ProjectTargetFramework" />
</MSBuild>
<!--
Calls the VSTestSingleTargetFramework target for each target framework using MSBuild batching.
-->
<MSBuild Projects="$(SolutionPath)"
BuildInParallel="false"
Targets="VSTestSingleTargetFramework"
ContinueOnError="ErrorAndContinue"
Properties="TargetFramework=%(ProjectTargetFramework.Identity);Platform=$(Platform);Configuration=$(Configuration)" />
</Target>
<!--
Runs tests for a single target framework.
-->
<Target Name="VSTestSingleTargetFramework"
DependsOnTargets="GetTestProjects;BuildTests">
<Message Text="Running $(TestType.ToLower()) tests for framework '$(TargetFramework)'..."
Importance="High" />
<!--
Gets a list of all projects that supported the specified framework.
-->
<MSBuild Projects="@(TestProject)"
Targets="DoesProjectSupportTargetFramework"
BuildInParallel="$(BuildInParallel)"
RemoveProperties="TargetFramework"
Properties="ProjectTargetFramework=$(TargetFramework)">
<Output TaskParameter="TargetOutputs"
ItemName="TestProjectForFramework" />
</MSBuild>
<!--
Gets a list of all supported target frameworks for each test project if no projects support the specified framework.
-->
<MSBuild Projects="@(TestProject)"
Targets="GetProjectTargetFrameworks"
BuildInParallel="$(BuildInParallel)"
RemoveProperties="TargetFramework"
Condition="@(TestProjectForFramework->Count()) == 0">
<Output TaskParameter="TargetOutputs"
ItemName="ProjectTargetFramework" />
</MSBuild>
<!--
Logs an error if no projects support the specified framework and shows what target framworks are supported.
-->
<Error Text="There are no tests that target '$(TargetFramework)', available target frameworks are '@(ProjectTargetFramework->Distinct(), '%27, %27')'"
Condition="@(TestProjectForFramework->Count()) == 0" />
<!--
Gets the full path to the test assembly for each test project.
-->
<MSBuild Projects="@(TestProjectForFramework)"
BuildInParallel="true"
Targets="GetTargetPath"
Properties="Platform=$(Platform);Configuration=$(Configuration);BuildingSolutionFile=true;CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents);SolutionDir=$(SolutionDir);SolutionExt=$(SolutionExt);SolutionFileName=$(SolutionFileName);SolutionName=$(SolutionName);SolutionPath=$(SolutionPath)">
<Output TaskParameter="TargetOutputs"
ItemName="TestAssembly" />
</MSBuild>
<Message Text="Only running tests from a single test project: @(TestProject)"
Importance="High"
Condition="'$(TestProjectName)' != ''" />
<ItemGroup>
<!--
Adds the console logger with verbosity and then adds any specified from the command-line.
-->
<VSTestLogger Include="console%3Bverbosity=$(VSTestVerbosity);$(VSTestLogger)" />
<TestAssembly Remove="@(TestAssembly)" Condition="'$(TestAssembly)' != '' And '%(TestAssembly.Identity)' != '$(TestAssembly)'" />
</ItemGroup>
<ItemGroup>
<VSTestCommand Include="dotnet test" />
<VSTestCommand Include="@(TestAssembly->'"%(Identity)"', ' ')" />
<VSTestCommand Include="--nologo" Condition="'$(VSTestNoLogo)' == 'true'" />
<VSTestCommand Include="--settings "$(VSTestSetting)"" Condition="'$(VSTestSetting)' != ''" />
<VSTestCommand Include="--ResultsDirectory "$(VSTestResultsDirectory)"" Condition="'$(VSTestResultsDirectory)' != ''" />
<VSTestCommand Include="--diag "$(BinlogDirectory)vstest.diag.log" " Condition="'$(BinlogDirectory)' != ''" />
</ItemGroup>
<!--
Runs the tests via 'dotnet test'.
-->
<Exec Command="@(VSTestCommand->'%(Identity)', ' ') --logger @(VSTestLogger->Distinct()->'"%(Identity)"', ' --logger ')"
IgnoreStandardErrorWarningFormat="true"
IgnoreExitCode="true"
LogStandardErrorAsError="false">
<Output TaskParameter="ExitCode"
PropertyName="VSTestExitCode" />
</Exec>
<Error Text="$(TestType) test run failed for framework '$(TargetFramework)'."
Condition="'$(VSTestExitCode)' != '0'" />
<Message Text="Finished $(TestType.ToLower()) tests for '$(TargetFramework)'"
Importance="High" />
</Target>
<!--
Trims down the list of projects when running 'dotnet test' to only include test projects.
-->
<Target Name="_SetRestoreGraphEntryPointsToTestProjects"
BeforeTargets="_LoadRestoreGraphEntryPoints"
DependsOnTargets="GetTestProjects"
Condition="'$(VSTestSessionCorrelationId)' != '' Or '$(TestType)' != ''">
<MSBuild Projects="@(TestProject)"
Targets="DoesProjectSupportTargetFramework"
BuildInParallel="$(BuildInParallel)"
RemoveProperties="TargetFramework"
Properties="ProjectTargetFramework=$(TargetFramework)"
Condition="'$(TargetFramework)' != ''">
<Output TaskParameter="TargetOutputs"
ItemName="TestProjectForFramework" />
</MSBuild>
<ItemGroup>
<RestoreGraphProjectInputItems Include="@(TestProjectForFramework)"
Condition="@(TestProjectForFramework->Count()) != 0"/>
<RestoreGraphProjectInputItems Include="@(TestProject)"
Condition="@(TestProjectForFramework->Count()) == 0"/>
</ItemGroup>
</Target>
<!--
Trims down the list of projects to build when running 'dotnet test' to only include test projects.
-->
<Target Name="_SetBuildProjectReferencesToTestProjects"
BeforeTargets="Build"
DependsOnTargets="GetTestProjects"
Condition="'$(TestType)' != ''">
<ItemGroup>
<ProjectReference Remove="@(ProjectReference)" />
<ProjectReference Include="@(TestProject)" />
</ItemGroup>
</Target>
</Project>