summaryrefslogtreecommitdiff
path: root/Tools/tests.targets
blob: 9852545a9ae9c7c72fc7adb15e16e084d2989220 (plain)
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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <!-- This is the target that copies the test assets to the test output -->
  <Import Project="$(MSBuildThisFileDirectory)publishtest.targets" />
  <Import Condition="'$(Performance)' != 'false'" Project="$(MSBuildThisFileDirectory)PerfTesting.targets" />
  <UsingTask TaskName="GenerateTestExecutionScripts" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll"/>
  <UsingTask TaskName="GetTargetMachineInfo" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll"/>
  <UsingTask Condition="'$(BuildingUAPVertical)' == 'true'" TaskName="ExtractResWResourcesFromAssemblies" AssemblyFile="$(BuildToolsTaskDir)Microsoft.DotNet.Build.Tasks.dll"/>

  <PropertyGroup>
    <SkipTestRun Condition="'$(IsTestProject)' != 'true' OR ('$(IsPerformanceTestProject)' == 'true' AND '$(Performance)' == 'false')">true</SkipTestRun>
    <TestDisabled Condition="'$(SkipTests)'=='true'">true</TestDisabled>
    <TestsSuccessfulSemaphore>tests.passed</TestsSuccessfulSemaphore>
    <!-- In case that TestPath is not yet set, default it here -->
    <TestPath Condition="'$(TestPath)'==''">$(OutDir)</TestPath>
  </PropertyGroup>

  <!--
    Copied from Microsoft.Net.Test.Sdk.targets which currently skips netstandard projects as 
    they are not intended to be executable. We override this as we launch the test assemblies
    directly with the runner. This is needed for VS debugging support.
    TODO: Fix VB test project reference to Test SDK.
  -->
  <PropertyGroup Condition="'$(IncludeVSTestReferences)' == 'true' AND '$(BuildingNETCoreAppVertical)' == 'true' AND '$(Language)' != 'VB'">
    <OutputType>Exe</OutputType>
    <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
    <GeneratedProgramFile Condition="'$(GeneratedProgramFile)' ==''">$(IntermediateOutputPath)$(MSBuildProjectName).Program$(DefaultLanguageSourceExtension)</GeneratedProgramFile>
    <GenerateProgramFile Condition="'$(GenerateProgramFile)' == ''">true</GenerateProgramFile>
  </PropertyGroup>

  <!-- In case that XunitPerfMaxIteration is not yet set, default it here -->
  <PropertyGroup>
    <XunitPerfMaxIteration Condition="'$(XunitPerfMaxIteration)'==''">1</XunitPerfMaxIteration>
    <XunitPerfMaxIterationInner Condition="'$(XunitPerfMaxIterationInner)'==''">1</XunitPerfMaxIterationInner>
  </PropertyGroup>

  <ItemGroup>
    <!-- Split semicolon separated lists -->
    <WithCategoriesItems Include="$(WithCategories)" />
    <WithoutCategoriesItems Include="$(WithoutCategories)" />
    <DefaultNoCategories Include="$(DefaultNoCategories)" />
    <UnsupportedPlatformsItems Include="$(UnsupportedPlatforms)"/>
  </ItemGroup>

  <!-- General xunit options -->
  <PropertyGroup>
    <XunitResultsFileName>testResults.xml</XunitResultsFileName>

    <_XunitOptions Condition="'$(BuildingNETFxVertical)' == 'true' and '$(XUnitNoAppdomain)' == 'true'">$(_XunitOptions) -noappdomain </_XunitOptions>
    <_XunitOptions>$(_XunitOptions) -xml $(XunitResultsFileName)</_XunitOptions>
    <_XunitOptions>$(_XunitOptions) -notrait category=non$(_bc_TargetGroup)tests</_XunitOptions>

    <TargetOS Condition="'$(TargetOS)' == ''">$(DefaultOSGroup)</TargetOS>
    <TargetOSTrait Condition="'$(TargetOS)'=='Windows_NT'">nonwindowstests</TargetOSTrait>
    <TargetOSTrait Condition="'$(TargetOS)'=='Linux'">nonlinuxtests</TargetOSTrait>
    <TargetOSTrait Condition="'$(TargetOS)'=='OSX'">nonosxtests</TargetOSTrait>
    <TargetOSTrait Condition="'$(TargetOS)'=='FreeBSD'">nonfreebsdtests</TargetOSTrait>
    <TargetOSTrait Condition="'$(TargetOS)'=='NetBSD'">nonnetbsdtests</TargetOSTrait>
    <_XunitOptions Condition="'$(TargetOSTrait)' != ''">$(_XunitOptions) -notrait category=$(TargetOSTrait)</_XunitOptions>

    <_XunitOptions Condition="'$(XunitMaxThreads)'!=''">$(_XunitOptions) -maxthreads $(XunitMaxThreads)</_XunitOptions>
    <_XunitOptions Condition="'$(XunitOptions)' != ''">$(_XunitOptions) $(XunitOptions)</_XunitOptions>
    <_XunitOptions Condition="'$(XunitMethodName)' != ''">$(_XunitOptions) -method $(XunitMethodName)</_XunitOptions>
    <_XunitOptions Condition="'$(XunitClassName)' != ''">$(_XunitOptions) -class $(XunitClassName)</_XunitOptions>
    <_XunitOptions Condition="'$(XunitShowProgress)' == 'true'">$(_XunitOptions) -verbose</_XunitOptions>

    <XunitTestAssembly Condition="'$(XunitTestAssembly)' == ''">$(TargetFileName)</XunitTestAssembly>
    <XunitArguments>$(XunitTestAssembly) $(_XunitOptions)</XunitArguments>
  </PropertyGroup>

  <!--
    Executable names and test invocation options.
    Used by CodeCoverage and GenerateTestExecutionScripts.
    Not used by UAP as we have our own launcher.
  -->
  <PropertyGroup Condition="'$(BuildingUAPVertical)' != 'true'">
    <XunitExecutableName>xunit.console</XunitExecutableName>
    <RemoteExecutorExecutableName>RemoteExecutorConsoleApp</RemoteExecutorExecutableName>

    <XunitExecutable Condition="'$(XunitExecutable)' == '' AND ('$(BuildingNETFxVertical)' == 'true' OR '$(UseDotNetNativeToolchain)' == 'true')">$(XunitExecutableName).exe</XunitExecutable>
    <XunitExecutable Condition="'$(XunitExecutable)' == ''">$(XunitExecutableName).dll</XunitExecutable>
    <RemoteExecutorExecutable>$(RemoteExecutorExecutableName).exe</RemoteExecutorExecutable>

    <TestProgram>$(XunitExecutable)</TestProgram>
    <TestArguments>$(XunitArguments)</TestArguments>
  </PropertyGroup>

  <!-- netcoreapp (not aot) uses the dotnet host. -->
  <PropertyGroup Condition="'$(BuildingNETCoreAppVertical)' == 'true' AND '$(UseDotNetNativeToolchain)' != 'true'">
    <TestHostExecutablePath Condition="'$(TestHostExecutablePath)' == '' AND '$(RunningOnUnix)' != 'true'">%RUNTIME_PATH%\dotnet.exe</TestHostExecutablePath>
    <TestHostExecutablePath Condition="'$(TestHostExecutablePath)' == '' AND '$(RunningOnUnix)' == 'true'">$RUNTIME_PATH/dotnet</TestHostExecutablePath>
    <TestProgram Condition="'$(BuildingNETCoreAppVertical)' == 'true'">$(TestHostExecutablePath)</TestProgram>
    <TestArguments Condition="'$(BuildingNETCoreAppVertical)' == 'true'">$(XunitExecutable) $(XunitArguments)</TestArguments>
  </PropertyGroup>

  <!--
    Inputs: TestProgram, TestArguments
    Outputs: TestCommandLine
  -->
  <Import Project="$(MSBuildThisFileDirectory)CodeCoverage.targets" />

  <!-- 
    Runtime config files.
    Can be overridden to supply customized configuration files (i.e. runtime switches).
  -->
  <PropertyGroup>
    <RuntimeConfigName Condition="'$(BuildingNETCoreAppVertical)' == 'true'">netcoreapp.runtimeconfig.json</RuntimeConfigName>
    <RuntimeConfigName Condition="'$(BuildingNETFxVertical)' == 'true'">DesktopRunnerConfigFile.config</RuntimeConfigName>
    <RuntimeConfigExtension Condition="'$(BuildingNETCoreAppVertical)' == 'true'">.runtimeconfig.json</RuntimeConfigExtension>
    <RuntimeConfigExtension Condition="'$(BuildingNETFxVertical)' == 'true'">.exe.config</RuntimeConfigExtension>
    <RuntimeConfigPath Condition="'$(BuildingNETCoreAppVertical)' == 'true' AND '$(RuntimeConfigPath)' == '' AND '$(CodeCoverageEnabled)' == 'true' AND '$(UseCoverageDedicatedRuntime)' == 'true'">$(ToolsDir)coverage/$(RuntimeConfigName)</RuntimeConfigPath>
    <RuntimeConfigPath Condition="'$(RuntimeConfigPath)' == ''">$(ToolsDir)$(RuntimeConfigName)</RuntimeConfigPath>

    <!-- Copy the app.config / runtimeSettings.json file into the OutDir if the project is an executable test project. -->
    <CopyConfigurationFiles Condition="'$(CopyConfigurationFiles)' == ''
                                  AND ('$(BuildingNETCoreAppVertical)' == 'true' OR '$(BuildingNETFxVertical)' == 'true')
                                  AND '$(IsTestProject)' == 'true'
                                  AND '$(IsInvokableTestProject)' != 'true'">true</CopyConfigurationFiles>
  </PropertyGroup>

  <ItemGroup Condition="'$(CopyConfigurationFiles)' == 'true'">
    <AllItemsFullPathWithTargetPath Include="$(RuntimeConfigPath)">
      <TargetPath>$(AssemblyName)$(RuntimeConfigExtension)</TargetPath>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </AllItemsFullPathWithTargetPath>
  </ItemGroup>

  <Target Name="DiscoverTestInputs" Condition="'$(IsInvokableTestProject)' == 'true'" DependsOnTargets="ResolveReferences;GetCopyToOutputDirectoryItems">
    <ItemGroup>
      <RunTestsForProjectInputs Include="@(ReferenceCopyLocalPaths)" />
      <RunTestsForProjectInputs Include="@(Content)" />
      <RunTestsForProjectInputs Include="@(IntermediateAssembly)" />
      <RunTestsForProjectInputs Include="@(_DebugSymbolsIntermediatePath)" />
      <RunTestsForProjectInputs Include="@(AllItemsFullPathWithTargetPath)" />
    </ItemGroup>

    <ItemGroup Condition="'$(SkipXunitDependencyCopying)' != 'true'">
      <SupplementalTestData Include="$(ToolsDir)xunit.runner.json" />
      <SupplementalTestData Include="$(RuntimePath)Microsoft.DotNet.XUnitExtensions.dll" />
      <SupplementalTestData Include="$(RuntimePath)xunit.assert.dll" />
      <SupplementalTestData Include="$(RuntimePath)xunit.core.dll" />
      <SupplementalTestData Include="$(RuntimePath)xunit.abstractions.dll" />
    </ItemGroup>

    <ItemGroup Condition="'$(BuildingNETCoreAppVertical)' == 'true'">
      <SupplementalTestData Condition="'$(IsPerformanceTestProject)' != 'true'" Include="$(RuntimeConfigPath)" DestinationName="$(XunitExecutableName).runtimeconfig.json" />
      <SupplementalTestData Condition="'$(IsPerformanceTestProject)' != 'true'" Include="$(RuntimePath)$(XunitExecutable)" />
      <SupplementalTestData Include="$(RuntimePath)xunit.execution.dotnet.dll" />
      <SupplementalTestData Include="$(RuntimePath)xunit.runner.reporters.netcoreapp10.dll" />
      <SupplementalTestData Include="$(RuntimePath)xunit.runner.utility.netcoreapp10.dll" />
      <SupplementalTestData Condition="'$(IncludeVSTestReferences)' == 'true'" Include="$(RuntimePath)xunit.runner.visualstudio.dotnetcore.testadapter.dll" />
    </ItemGroup>

    <ItemGroup Condition="'$(BuildingNETFxVertical)' == 'true'">
      <!--
        We need to generate a simple config file for desktop test executors to tell them to use DEVPATH environment variable to use their dependencies from there.
        DEVPATH is being set for desktop runs in RunTests.cmd to the TestHostPath. We need this approach to have desktop Helix runs.
      -->
      <SupplementalTestData Condition="'$(IsPerformanceTestProject)' != 'true'" Include="$(RuntimeConfigPath)" DestinationName="$(XunitExecutable).config" />
      <SupplementalTestData Condition="'$(IsPerformanceTestProject)' != 'true'" Include="$(RuntimePath)$(XunitExecutable)" />
      <SupplementalTestData Include="$(RuntimePath)xunit.execution.desktop.dll" />
      <SupplementalTestData Include="$(RuntimePath)xunit.runner.reporters.net452.dll" />
      <SupplementalTestData Include="$(RuntimePath)xunit.runner.utility.net452.dll" />
      <SupplementalTestData Condition="'$(IncludeVSTestReferences)' == 'true'" Include="$(RuntimePath)xunit.runner.visualstudio.testadapter.dll" />
    </ItemGroup>
  </Target>

  <Target Name="AddDefaultTestReferences" BeforeTargets="SetupDefaultReferences" Condition="'$(IsTestProject)' == 'true'">
    <ItemGroup Condition="'$(IncludeDefaultReferences)' == 'true'">
      <TargetingPackExclusions Include="System.Runtime.WindowsRuntime.UI.Xaml" /> <!-- Harmless, but causes PRI targets to run -->
      <TargetingPackExclusions Include="@(ReferenceFromRuntime)"/>

      <!-- Reference everything in the targeting pack directory -->
      <TargetingPackItems Include="%(TargetingPackDirs.Identity)/*.dll" />

      <DefaultReference Include="%(TargetingPackItems.Filename)" Exclude="@(TargetingPackExclusions)" />
    </ItemGroup>

    <!-- Default test references that are ok to reference. -->

    <!-- xunit -->
    <ItemGroup>
      <ReferenceFromRuntime Include="Microsoft.DotNet.XUnitExtensions" />
      <ReferenceFromRuntime Include="xunit.abstractions" />
      <ReferenceFromRuntime Include="xunit.assert" />
      <ReferenceFromRuntime Include="xunit.core" />
    </ItemGroup>

    <!-- perf -->
    <ItemGroup Condition="'$(IsPerformanceTestProject)' == 'true'">
      <ReferenceFromRuntime Include="xunit.performance.api" />
      <ReferenceFromRuntime Include="xunit.performance.core" />
    </ItemGroup>
    
    <ItemGroup Condition="'$(IsBenchmarkDotNetProject)' == 'true'">
      <ReferenceFromRuntime Include="BenchmarkDotNet" />
      <ReferenceFromRuntime Include="BenchmarkDotNet.Diagnostics.Windows" />
    </ItemGroup>

    <!-- vs debugging / test explorer -->
    <ItemGroup Condition="'$(IncludeVSTestReferences)' == 'true' AND '$(BuildingNETCoreAppVertical)' == 'true'">
      <ReferenceFromRuntime Include="Microsoft.DotNet.PlatformAbstractions" />
      <ReferenceFromRuntime Include="Microsoft.Extensions.DependencyModel" />
      <ReferenceFromRuntime Include="Microsoft.TestPlatform.CommunicationUtilities" />
      <ReferenceFromRuntime Include="Microsoft.TestPlatform.CoreUtilities" />
      <ReferenceFromRuntime Include="Microsoft.TestPlatform.CrossPlatEngine" />
      <ReferenceFromRuntime Include="Microsoft.TestPlatform.PlatformAbstractions" />
      <ReferenceFromRuntime Include="Microsoft.VisualStudio.CodeCoverage.Shim" />
      <ReferenceFromRuntime Include="Microsoft.VisualStudio.TestPlatform.Common" />
      <ReferenceFromRuntime Include="Microsoft.VisualStudio.TestPlatform.ObjectModel" />
      <ReferenceFromRuntime Include="testhost" />
      <ReferenceFromRuntime Include="xunit.runner.visualstudio.dotnetcore.testadapter" />
    </ItemGroup>

    <ItemGroup Condition="'$(IncludeVSTestReferences)' == 'true' AND ('$(BuildingUAPVertical)' == 'true' OR '$(BuildingUAPAOTVertical)' == 'true')">
      <ReferenceFromRuntime Include="testhost" />
      <ReferenceFromRuntime Include="xunit.runner.visualstudio.uwp.testadapter" />
    </ItemGroup>

    <ItemGroup Condition="'$(IncludeVSTestReferences)' == 'true' AND '$(BuildingNETFxVertical)' == 'true'">
      <ReferenceFromRuntime Include="Microsoft.VisualStudio.CodeCoverage.Shim" />
      <ReferenceFromRuntime Include="xunit.runner.visualstudio.testadapter" />
    </ItemGroup>
  </Target>

  <!-- Properties needed to create resources.pri for UAP runner -->
  <PropertyGroup Condition="'$(BuildingUAPVertical)' == 'true'">
    <_CommonPriFile Condition="'$(_CommonPriFile)' == ''">$(RuntimePath)resw/resources.pri</_CommonPriFile>
    <_TestSpecificPriFile>$(TestPath)resources.pri</_TestSpecificPriFile>
    <_MakePriExecutable>$(ToolsDir)net46/makepri.exe</_MakePriExecutable>
    <_MakePriHelpersDir>$(IntermediateOutputPath)makepri</_MakePriHelpersDir>
    <_MakePriConfigTemplate>$(ToolsDir)MakePriConfigFile.xml</_MakePriConfigTemplate>
    <_MakePriConfigFile>$(_MakePriHelpersDir)/ModifiedConfigFile.xml</_MakePriConfigFile>
    <_ReswListFile>$(_MakePriHelpersDir)/reswlist.RESFILES</_ReswListFile>
    <_PriListFile>$(_MakePriHelpersDir)/prilist.RESFILES</_PriListFile>
    <_ExternalReswOutputPath>$(ResourcesFolderPath)/external/</_ExternalReswOutputPath>
  </PropertyGroup>

  <ItemGroup Condition="'$(BuildingUAPVertical)' == 'true'">
    <_AllRuntimeDllFiles Include="$(RuntimePath)\*.dll" Exclude="$(RuntimePath)\Microsoft.VisualStudio.TestPlatform.*dll;$(RuntimePath)\Microsoft.TestPlatform.*dll" />
    <_ExternalReswFiles Include="$(_ExternalReswOutputPath)*.resw" Exclude="$(RuntimePath)\Microsoft.VisualStudio.TestPlatform.*resw;$(RuntimePath)\Microsoft.TestPlatform.*resw" />

    <!-- The first time the CreateReswFilesForExternalDependencies target is executed the itemgroup _ExternalReswFiles will be empty
    and that will avoid the target from executing, so we add a dummy file if they are empty so that the target is executed the first time. -->
    <_ExternalReswFiles Condition="@(_ExternalReswFiles) == ''" Include="$(_ExternalReswOutputPath)dummy.resw" />
  </ItemGroup>

  <Target Name="CreateReswFilesForExternalDependencies"
          Condition="'$(BuildingUAPVertical)' == 'true' AND '$(ShouldSkipExternalResources)' != 'true'"
          Inputs="@(_AllRuntimeDllFiles)"
          Outputs="@(_ExternalReswFiles)">

    <ExtractResWResourcesFromAssemblies InputAssemblies="@(_AllRuntimeDllFiles)"
                                        OutputPath="$(_ExternalReswOutputPath)"
                                        InternalReswDirectory="$(ResourcesFolderPath)" />

  </Target>

  <!-- This target the necessary config file in order to create the UAP runner's resources.pri file using MakePri.exe -->
  <Target Name="CreateMakePriConfigFileFromTemplate"
          Condition="'$(BuildingUAPVertical)' == 'true'"
          Inputs="$(_MakePriConfigTemplate)"
          Outputs="$(_MakePriConfigFile)">

    <MakeDir Directories="$(_MakePriHelpersDir)" />

    <WriteLinesToFile File="$(_MakePriConfigFile)"
                      Lines="$([System.IO.File]::ReadAllText('$(_MakePriConfigTemplate)').Replace('{reswfilelist}', '$(_ReswListFile)').Replace('{prireslist}', '$(_PriListFile)'))"
                      Overwrite="true" />

    <ItemGroup>
      <FileWrites Include="$(_MakePriConfigFile)" />
    </ItemGroup>

  </Target>

  <!-- This target gets all the resw files to be used to create the UAP runner's resources.pri file -->
  <Target Name="CalculateResWFiles"
          Condition="'$(BuildingUAPVertical)' == 'true'"
          DependsOnTargets="CreateReswFilesForExternalDependencies">

    <ItemGroup>
      <_TestResWFiles Include="$(TestResourcesFolderPath)\*.resw" Exclude="$(TestResourcesFolderPath)\Microsoft.VisualStudio.TestPlatform.*resw;$(TestResourcesFolderPath)\Microsoft.TestPlatform.*resw" />
      <_CommonResWFiles Include="$(ResourcesFolderPath)\**\*.resw" Exclude="$(ResourcesFolderPath)\**\Microsoft.VisualStudio.TestPlatform.*resw;$(ResourcesFolderPath)\**\Microsoft.TestPlatform.*resw" />
    </ItemGroup>
  </Target>

  <!-- This target creates a resources.pri file that contains all the framework resources, this is a common file used by all of our test assemblies that have no specific resources. -->
  <Target Name="MakeCommonResourcesPriFile"
          DependsOnTargets="CalculateResWFiles;CreateMakePriConfigFileFromTemplate"
          Condition="'$(BuildingUAPVertical)' == 'true'"
          Inputs="@(_CommonResWFiles)"
          Outputs="$(_CommonPriFile)">

    <!-- We write the list of resw files that have to be indexed by makepri.exe -->
    <WriteLinesToFile File="$(_ReswListFile)"
                      Lines="@(_CommonResWFiles)"
                      Overwrite="true" />

    <!-- We write the list of base pri files to merge with the resw files by makepri.exe -->
    <WriteLinesToFile File="$(_PriListFile)"
                      Lines="$(TestHostRootPath)\Runner\resources.pri"
                      Overwrite="true" />

    <PropertyGroup>
      <_MakePriCommand>$(_MakePriExecutable) versioned /o /pr "$(TestHostRootPath)\Runner" /cf "$(_MakePriConfigFile)" /of "$(_CommonPriFile)" /if "$(TestHostRootPath)\Runner\resources.pri"</_MakePriCommand>
    </PropertyGroup>

    <!-- We call MakePri.exe to create common resources.pri file -->
    <Exec Command="$(_MakePriCommand)" StandardOutputImportance="Low" StdErrEncoding="Unicode"/>

    <ItemGroup>
      <FileWrites Include="$(_CommonPriFile)" />
    </ItemGroup>

  </Target>

  <!-- This target creates the resources.pri file for every test assembly in order to be able to run the tests inside an appx. -->
  <Target Name="MakeTestSpecificResourcesPriFile"
          DependsOnTargets="MakeCommonResourcesPriFile"
          Condition="'$(BuildingUAPVertical)' == 'true'">

    <!-- We write the list of resw files that have to be indexed by makepri.exe only if this test project has its own resources. -->
    <WriteLinesToFile Condition="'$(TestProjectNeedsModifiedPriFile)' == 'true'"
                      File="$(_ReswListFile)"
                      Lines="@(_TestResWFiles)"
                      Overwrite="true" />

    <!-- We write the list of base pri files to merge with the resw files by makepri.exe only if this test project has its own resources. -->
    <WriteLinesToFile Condition="'$(TestProjectNeedsModifiedPriFile)' == 'true'"
                      File="$(_PriListFile)"
                      Lines="$(_CommonPriFile)"
                      Overwrite="true" />

    <PropertyGroup Condition="'$(TestProjectNeedsModifiedPriFile)' == 'true'">
      <_MakePriCommand>$(_MakePriExecutable) versioned /o /pr "$(RuntimePath)resw" /cf "$(_MakePriConfigFile)" /of "$(TestPath)" /if "$(_CommonPriFile)"</_MakePriCommand>
    </PropertyGroup>

    <!-- We call MakePri.exe to create common resources.pri file only if this test project has its own resources. -->
    <Exec Command="$(_MakePriCommand)" StandardOutputImportance="Low" StdErrEncoding="Unicode" Condition="'$(TestProjectNeedsModifiedPriFile)' == 'true'" />

    <Copy Condition="'$(TestProjectNeedsModifiedPriFile)' != 'true' AND Exists('$(_CommonPriFile)')"
          SourceFiles="$(_CommonPriFile)"
          DestinationFiles="$(TestPath)\resources.pri"
          SkipUnchangedFiles="true" />

    <Copy Condition="'$(TestProjectNeedsModifiedPriFile)' != 'true' AND !Exists('$(_CommonPriFile)')"
          SourceFiles="$(TestHostRootPath)\Runner\resources.pri"
          DestinationFiles="$(TestPath)\resources.pri"
          SkipUnchangedFiles="true" />

  </Target>

  <!-- Generate the script to run the tests.  The script performs two high-level steps:
       1.  Copies the common test runtime dependencies calculated in DiscoverTestDependencies to the test
           execution directory. Each copy command no-ops if the file already exists in the test execution
           directory.
       2.  Runs the tests. -->
  <Target Name="GenerateTestExecutionScripts"
          DependsOnTargets="SetupTestProperties;MakeTestSpecificResourcesPriFile;MakeCommonResourcesPriFile">
    <Error Condition="'$(TargetOSTrait)' == ''" Text="TargetOS [$(TargetOS)] is unknown so we don't know how to configure the test run for this project [$(MSBuildProjectName)]" />

    <PropertyGroup>
      <RunnerScriptName Condition="'$(TargetOS)' == 'Windows_NT'">RunTests.cmd</RunnerScriptName>
      <RunnerScriptName Condition="'$(TargetOS)' != 'Windows_NT'">RunTests.sh</RunnerScriptName>

      <!-- In UAP we don't want the repro steps printed -->
      <RunnerTemplateName Condition="'$(TargetOS)' == 'Windows_NT' AND '$(BuildingUAPVertical)' != 'true'">RunnerTemplate.Windows.txt</RunnerTemplateName>
      <RunnerTemplateName Condition="'$(TargetOS)' == 'Windows_NT' AND ('$(BuildingUAPVertical)' == 'true' OR '$(UseDotNetNativeToolchain)' == 'true')">RunnerTemplate.Quiet.Windows.txt</RunnerTemplateName>
      <RunnerTemplateName Condition="'$(TargetOS)' != 'Windows_NT' AND '$(BuildingUAPVertical)' != 'true'">RunnerTemplate.Unix.txt</RunnerTemplateName>
      <RunnerTemplateName Condition="'$(TargetOS)' != 'Windows_NT' AND ('$(BuildingUAPVertical)' == 'true' OR '$(UseDotNetNativeToolchain)' == 'true')">RunnerTemplate.Quiet.Unix.txt</RunnerTemplateName>
    </PropertyGroup>

    <PropertyGroup>
      <XunitTraitOptions Condition="'@(RunWithTraits)'!=''">$(XunitTraitOptions) -trait category=@(RunWithTraits, ' -trait category=') </XunitTraitOptions>
      <XunitTraitOptions Condition="'@(RunWithoutTraits)'!=''">$(XunitTraitOptions) -notrait category=@(RunWithoutTraits, ' -notrait category=') </XunitTraitOptions>
    </PropertyGroup>

      <!-- TestCommandLine isn't used for performance runs. Not overriding when already set by CodeCoverage and UAP. -->
      <PropertyGroup Condition="'$(TestCommandLine)' == '' AND '$(BuildingUAPVertical)' != 'true' AND '$(IsPerformanceTestProject)' != 'true'">
        <TestCommandLine>$(TestProgram) $(TestArguments) {XunitTraitOptions}</TestCommandLine>

        <!-- Set $(TestDebugger) to eg c:\debuggers\windbg.exe to run tests under a debugger. -->
        <TestCommandLine Condition="'$(TestDebugger)' != '' and !$(TestDebugger.Contains('devenv'))">$(TestDebugger) $(TestCommandLine)</TestCommandLine>
        <TestCommandLine Condition="'$(TestDebugger)' != '' and  $(TestDebugger.Contains('devenv'))">$(TestDebugger) /debugexe $(TestCommandLine)</TestCommandLine>
      </PropertyGroup>

    <!-- Replace the {XunitTraitOptions} place holder with the actual traits.  We use the place holder
         because code coverage needs to have a bit of the test command line after the traits (it adds ending quotes
         to one of its options).  Simply appending the traits would break code coverage.
         Additionally, replace CoreRun.exe with ./corerun on Non-Windows OSes (this is the only difference in the command)
         Future refactoring will allow us to construct this correctly initially, but we don't always know the TargetOS
         when the properties are set currently. -->
    <PropertyGroup>
      <TestCommandLine>$(TestCommandLine.Replace('{XunitTraitOptions}', '$(XunitTraitOptions)'))</TestCommandLine>

      <!-- We also need to replace {CoverageFilter} with its true value, which should be evaluated correctly at this point. -->
      <TestCommandLine>$(TestCommandLine.Replace('{CoverageFilter}', '$(CoverageFilter)'))</TestCommandLine>

      <OutputFolderForScriptGenerator>$(TestPath)</OutputFolderForScriptGenerator>
      <OutputPathForScriptGenerator>$(OutputFolderForScriptGenerator)/$(RunnerScriptName)</OutputPathForScriptGenerator>
      <OutputFolderForTestDependencies>$(BinDir)/TestDependencies</OutputFolderForTestDependencies>
    </PropertyGroup>

    <MakeDir Condition="'$(CoverageEnabledForProject)'=='true'" Directories="$(CoverageReportDir)" />

    <MakeDir Directories="$(OutputFolderForTestDependencies)" />
    <PropertyGroup>
      <_TestDependencyListRoot>$(MSBuildProjectName)-$(TestConfiguration)</_TestDependencyListRoot>
      <_TestDependencyListFileName>$(_TestDependencyListRoot).dependencylist.txt</_TestDependencyListFileName>
      <TestDependencyListFilePath>$(OutputFolderForTestDependencies)/$(_TestDependencyListFileName)</TestDependencyListFilePath>
    </PropertyGroup>
    <Message Text="Generating $(TestDependencyListFilePath)" />
    <WriteLinesToFile
      File="$(TestDependencyListFilePath)"
      Lines="@(IncludedFileForRunnerScript -> '%(PackageRelativePath)')"
      Overwrite="true"
      Encoding="Ascii" />

    <!--======================================================
                      Section for netfx test runs
          ====================================================== -->
    <ItemGroup Condition="'$(BuildingNETFxVertical)' == 'true'" >
      <TestCommandLines Include="set DEVPATH=%RUNTIME_PATH%" />
    </ItemGroup>

    <!--======================================================
                      Section for aot ilc test runs
            ====================================================== -->
    <PropertyGroup Condition="'$(UseDotNetNativeToolchain)' == 'true' AND '$(IsPerformanceTestProject)' != 'true'">
      <ILCBuildType Condition="'$(ILCBuildType)' == ''">ret</ILCBuildType>
      <_UseSharedAssemblies Condition="'$(EnableMultiFileILCTests)' == 'true'">-useSharedAssemblies</_UseSharedAssemblies>
      <_TestILCFolder>%RUNTIME_PATH%\TestILC</_TestILCFolder>
      <_Runtime_Path>%RUNTIME_PATH%\ILCInputFolder\</_Runtime_Path>
      <_ILCWin32 Condition="'$(BuildingUAPAOTVertical)'!='true'">-win32</_ILCWin32>
      <!-- Currently (and probably forever) we can't build AOT on ARM,
           So if we're running on ARM, what we really want to do is encapsulate
           the test command into a script that can be run on another machine -->
      <TestCommandLine Condition="'$(ArchGroup)'=='arm'">echo $(TestCommandLine)> .\RunContinuation.cmd </TestCommandLine>
    </PropertyGroup>

    <ItemGroup Condition="'$(UseDotNetNativeToolchain)' == 'true' AND '$(IsPerformanceTestProject)'!='true'" >
      <TargetExecutableNames Include="$(XunitExecutable)"/>
      <TargetExecutableNames Condition="'%(ProjectReference.Filename)' == 'RemoteExecutorConsoleApp'" Include="$(RemoteExecutorExecutable)"/>
      <IlcInputFolderContents Include="$(ILCFXInputFolder)/*" Exclude="$(ILCFXInputFolder)/**/$(XunitExecutableName).dll" />

      <TestCommandLines Include="if not exist %(IlcInputFolderContents.Filename)%(IlcInputFolderContents.Extension) mklink /H %(IlcInputFolderContents.Filename)%(IlcInputFolderContents.Extension) $(_Runtime_Path)%(IlcInputFolderContents.Filename)%(IlcInputFolderContents.Extension) 1> NUL" />
      <TestCommandLines Include="copy /y $(_TestILCFolder)\default.rd.xml %EXECUTION_DIR%" />
      <!-- Need to rename dll with entrypoint to exe for ilc to be satisfied -->
      <TestCommandLines Include="copy /y $(_Runtime_Path)$(XunitExecutableName).dll $(XunitExecutable)" />
      <TestCommandLines Include="if exist %EXECUTION_DIR%int rmdir /S /Q %EXECUTION_DIR%int" />
      <TestCommandLines Include="if exist %EXECUTION_DIR%native rmdir /S /Q %EXECUTION_DIR%native" />
      <TestCommandLines Include="@(TargetExecutableNames -> '
call %RUNTIME_PATH%\TestILC\ilc.exe -ExeName %(Identity) -in %EXECUTION_DIR% -out %EXECUTION_DIR%int\%(Identity)\ -usedefaultpinvoke:false -buildtype $(ILCBuildType) -v diag $(_UseSharedAssemblies) $(_ILCWin32)
set ILCERRORLEVEL=%ERRORLEVEL%
if NOT [%ILCERRORLEVEL%] == [0] exit /b %ILCERRORLEVEL%
robocopy /S /NP %EXECUTION_DIR%int\%(Identity)\ %EXECUTION_DIR%native\
')"/>
      <TestCommandLines Include="copy /y $(_TestILCFolder)\CRT\vcruntime140_app.dll %EXECUTION_DIR%native" />
      <TestCommandLines Include="echo > %EXECUTION_DIR%\native\$(XunitTestAssembly)"/>
      <TestCommandLines Include="cd native"/>

      <!-- These will cause failures if execution is skipped, such as on ARM -->
      <PostExecutionTestCommandLines Condition="'$(ArchGroup)' != 'arm'" Include="copy /y testResults.xml %EXECUTION_DIR%\" />
    </ItemGroup>

    <!--======================================================
                      Section for uap F5 test runs
            ====================================================== -->
    <PropertyGroup Condition="'$(BuildingUAPVertical)' == 'true' AND '$(IsPerformanceTestProject)' != 'true'">
      <!-- The location where the logs will be written by the test runner -->
      <UAP_Results_Path Condition="'$(UAP_Results_Path)'==''">%USERPROFILE%\Documents\TestResults\</UAP_Results_Path>

      <!-- Don't remove that trailing slash as helix might pass a path without one at the end. -->
      <_Runtime_Path>%RUNTIME_PATH%\UAPLayout\</_Runtime_Path>
      <!-- Make sure the path only has one type of slashes -->
      <_Runtime_Path>$(_Runtime_Path.Replace('/', '\'))</_Runtime_Path>

      <!-- The test execution command is different for UAP. -->
      <TestCommandLine>XUnitRunnerUap $(XunitArguments) $(XunitTraitOptions)</TestCommandLine>
    </PropertyGroup>

    <ItemGroup Condition="'$(BuildingUAPVertical)' == 'true' AND '$(IsPerformanceTestProject)' != 'true'" >
      <!-- Copy the runner files into the test directory -->
      <RunnerFolderContents Include="$(TestHostRootPath)\Runner\**\*" Exclude="$(TestHostRootPath)\Runner\**\*.pri"/>

      <TestCommandLines Include="if not exist Assets mkdir Assets" />
      <TestCommandLines Include="if not exist entrypoint mkdir entrypoint" />
      <TestCommandLines Include="if not exist Properties mkdir Properties" />
      <TestCommandLines Include="if not exist WinMetadata mkdir WinMetadata" />
      <TestCommandLines Include="if not exist %(RunnerFolderContents.RecursiveDir)%(RunnerFolderContents.Filename)%(RunnerFolderContents.Extension) mklink /H %(RunnerFolderContents.RecursiveDir)%(RunnerFolderContents.Filename)%(RunnerFolderContents.Extension) %RUNTIME_PATH%\Runner\%(RunnerFolderContents.RecursiveDir)%(RunnerFolderContents.Filename)%(RunnerFolderContents.Extension) 1> NUL" />

      <!-- Copy the runtime binaries over -->
      <RuntimePathContents Include="$(TestHostRootPath)\UAPLayout\*"/>
      <TestCommandLines Include="if not exist %(RuntimePathContents.RecursiveDir)%(RuntimePathContents.Filename)%(RuntimePathContents.Extension) mklink /H %(RuntimePathContents.RecursiveDir)%(RuntimePathContents.Filename)%(RuntimePathContents.Extension) $(_Runtime_Path)%(RuntimePathContents.Filename)%(RuntimePathContents.Extension) 1> NUL" />

      <!-- We need to have the ni as well as the non-ni version of the binary. The host (being a rather old build) looks for the ni name first (so we need that as well for now.) -->
      <TestCommandLines Include="copy /y $(_Runtime_Path)System.Private.CoreLib.dll System.Private.CoreLib.ni.dll" />

      <!-- Install -->
      <TestCommandLines Include="call %RUNTIME_PATH%\Launcher\WindowsStoreAppLauncher.exe -install appxmanifest.xml $(XunitArguments) $(XunitTraitOptions)" />
      <TestCommandLines Include="echo." />
      
      <!-- Uninstall -->
      <PostExecutionTestCommandLines Include="echo." />
      <!-- Save error level as the uninstall command overwrites the global one. -->
      <PostExecutionTestCommandLines Include="set ERRORLEVEL=%ERRORLEVEL%" />
      <PostExecutionTestCommandLines Include="call %RUNTIME_PATH%\Launcher\WindowsStoreAppLauncher.exe -uninstall appxmanifest.xml $(XunitArguments) $(XunitTraitOptions)" />

      <!-- Copy the log files and the results files from the Documents folder to the test folder -->
      <PostExecutionTestCommandLines Include="move /Y $(UAP_Results_Path)$(XunitTestAssembly).xml .\$(XunitResultsFileName)" />
    </ItemGroup>

    <!-- If the PreExecutionTestScript property is set, then it should be set to the full path to a script that will be directly incorporated
         into the generated runtests script, immediately before the test is run. This can be used to set a number of JIT stress modes,
         for example. It is intended that this be as late as possible in the generated script, as close as possible to the running of the
         test. That is why this doesn't appear higher in this file. The idea is that if the included script alters managed code behavior, such as
         setting various JIT stress modes, we don't want those changes to affect any other managed code invocation (such as test infrastructure
         written in managed code).
     -->
    <ItemGroup Condition="'$(PreExecutionTestScript)'!=''">
      <TestCommandLines Include="$([System.IO.File]::ReadAllText('$(PreExecutionTestScript)'))" />
    </ItemGroup>

    <ItemGroup Condition="'$(IsPerformanceTestProject)'!='true'">
      <!-- On Windows, call prevents the test command from making execution end prematurely -->
      <TestCommandLines  Condition="'$(TargetOS)'=='Windows_NT' and '$(TestGCStressLevel)' != ''" Include="set COMPlus_GCStress=$(TestGCStressLevel)"/>
      <TestCommandLines  Condition="'$(TargetOS)'=='Windows_NT' and '$(OuterLoop)' == 'true'" Include="set XUNIT_PERFORMANCE_MIN_ITERATION=1"/>
      <TestCommandLines  Condition="'$(TargetOS)'=='Windows_NT' and '$(OuterLoop)' == 'true'" Include="set XUNIT_PERFORMANCE_MAX_ITERATION=$(XunitPerfMaxIteration)"/>
      <TestCommandLines  Condition="'$(TargetOS)'=='Windows_NT' and '$(OuterLoop)' == 'true'" Include="set XUNIT_PERFORMANCE_MAX_ITERATION_INNER_SPECIFIED=$(XunitPerfMaxIterationInner)"/>
      <TestCommandLines  Condition="'$(TargetOS)'=='Windows_NT'" Include="call $(TestCommandLine)"/>

      <TestCommandLines  Condition="'$(TargetOS)'!='Windows_NT' and '$(TestGCStressLevel)' != ''" Include="export COMPlus_GCStress=$(TestGCStressLevel)"/>
      <TestCommandLines  Condition="'$(TargetOS)'!='Windows_NT' and '$(OuterLoop)' == 'true'" Include="export XUNIT_PERFORMANCE_MIN_ITERATION=1"/>
      <TestCommandLines  Condition="'$(TargetOS)'!='Windows_NT' and '$(OuterLoop)' == 'true'" Include="export XUNIT_PERFORMANCE_MAX_ITERATION=$(XunitPerfMaxIteration)"/>
      <TestCommandLines  Condition="'$(TargetOS)'!='Windows_NT' and '$(OuterLoop)' == 'true'" Include="export XUNIT_PERFORMANCE_MAX_ITERATION_INNER_SPECIFIED=$(XunitPerfMaxIterationInner)"/>
      <!-- Executables restored with .NET Core 2.0 do not have executable permission flags. https://github.com/NuGet/Home/issues/4424 -->
      <TestCommandLines  Condition="'$(TargetOS)'!='Windows_NT'" Include="chmod +x $(TestProgram)"/>
      <TestCommandLines  Condition="'$(TargetOS)'!='Windows_NT'" Include="$(TestCommandLine)"/>
    </ItemGroup>

    <ItemGroup Condition ="'$(IsPerformanceTestProject)'=='true'">
      <TestCommandLines Include="@(PerfTestCommandLines)" />
    </ItemGroup>

    <!-- Do not put anything between this Item Group and the GenerateTestExecutionScripts invocation -->
    <ItemGroup>
      <TestCommandLines Include="@(PostExecutionTestCommandLines)" />
    </ItemGroup>

    <GenerateTestExecutionScripts
      TestCommands="@(TestCommandLines)"
      TestDependencies="@(DontIncludeAnything)"
      RunnerScriptTemplate="$(MSBuildThisFileDirectory)/$(RunnerTemplateName)"
      ScriptOutputPath ="$(OutputPathForScriptGenerator)"
    />
    <!-- Executables restored with .NET Core 2.0 do not have executable permission flags. https://github.com/NuGet/Home/issues/4424 -->
    <Exec Condition="'$(TargetOS)'!='Windows_NT'" Command="chmod +x $(OutputPathForScriptGenerator)" />
  </Target>

  <Target Name="RunTestsForProject"
          Condition="'$(TestDisabled)' != 'true'"
          DependsOnTargets="CheckTestCategories"
          Inputs="@(RunTestsForProjectInputs)"
          Outputs="$(TestsSuccessfulSemaphore);$(TestPath)/$(XunitResultsFileName);$(CoverageOutputFilePath)"
          >

    <MakeDir Condition="'$(CoverageEnabledForProject)'=='true'" Directories="$(CoverageReportDir)" />
    <Error Text="TestILCFolder property is required for running aot tests. Please pass in the full path to the directory that contains ilc.exe to msbuild using /p:TestILCFolder=path_to_ilc_dir.exe" Condition="'$(UseDotNetNativeToolchain)'=='true' AND !Exists('$(TestHostRootPath)\TestILC')" />

    <!-- For UAP, make sure the Runner and Launcher folder exist, otherwise the tests cannot run -->
    <Error Text="We cannot run the tests for UAP because either the Runner or the Launcher could not be found. You need to specify the UAPToolsFolder property when calling build.cmd to fix this."
          Condition="'$(BuildingUAPVertical)'=='true' and (!Exists('$(TestHostRootPath)\Runner') or !Exists('$(TestHostRootPath)\Launcher'))" />

    <Exec Command="$(TestPath)/$(RunnerScriptName) $(TestHostRootPath)"
          CustomErrorRegularExpression="Failed: [^0]"
          ContinueOnError="true"
          IgnoreStandardErrorWarningFormat="true"
          >
      <Output PropertyName="TestRunExitCode" TaskParameter="ExitCode" />
    </Exec>

    <Error Condition="'$(TestRunExitCode)' != '0'" Text="One or more tests failed while running tests from '$(MSBuildProjectName)' please check $(TestPath)$(XunitResultsFileName) for details!" />
    <Touch Condition="'$(TestRunExitCode)' == '0'" Files="$(TestsSuccessfulSemaphore)" AlwaysCreate="true" />
  </Target>

  <!-- Needs to run before RunTestsForProject target as it computes categories and set TestDisabled -->
  <Target Name="CheckTestCategories">

    <!-- Default behavior is to disable OuterLoop and failing tests if not specified in WithCategories. -->
    <ItemGroup>
      <DefaultNoCategories Condition="'$(Outerloop)'!='true'" Include="OuterLoop" />
      <DefaultNoCategories Include="failing" />
      <WithoutCategoriesItems Include="@(DefaultNoCategories)" Exclude="@(WithCategoriesItems)" />
      <WithoutCategoriesItemsDistinct Include="@(WithoutCategoriesItems->Distinct())" />
    </ItemGroup>

    <ItemGroup>
      <RunWithTraits Condition="'@(WithCategoriesItems)'!=''" Include="@(WithCategoriesItems)" />
      <RunWithoutTraits Condition="'@(WithoutCategoriesItemsDistinct)'!=''" Include="@(WithoutCategoriesItemsDistinct)" />
    </ItemGroup>

    <PropertyGroup>
      <TestsSuccessfulSemaphore Condition="'@(RunWithTraits)' != ''">$(TestsSuccessfulSemaphore).with.@(RunWithTraits, '.')</TestsSuccessfulSemaphore>
      <TestsSuccessfulSemaphore Condition="'@(RunWithoutTraits)' != ''">$(TestsSuccessfulSemaphore).without.@(RunWithoutTraits, '.')</TestsSuccessfulSemaphore>
      <TestsSuccessfulSemaphore>$(TestPath)/$(TestsSuccessfulSemaphore)</TestsSuccessfulSemaphore>
    </PropertyGroup>

    <Delete Condition="'$(ForceRunTests)'=='true' And Exists($(TestsSuccessfulSemaphore))"
            Files="$(TestsSuccessfulSemaphore)" />
  </Target>

  <Target Name="CheckTestPlatforms">
    <PropertyGroup>
      <TestDisabled Condition="'%(UnsupportedPlatformsItems.Identity)' == '$(TargetOS)' Or '$(ConfigurationErrorMsg)' != ''">true</TestDisabled>
    </PropertyGroup>
    <Message Text="CheckTestPlatforms found TargetOS of [$(TargetOS)]." Importance="Low" />
    <Message Condition="'%(UnsupportedPlatformsItems.Identity)' == '$(TargetOS)'"
      Text="Skipping tests in $(AssemblyName) because it is not supported on $(TargetOS)" />
    <Message Condition="'$(ConfigurationErrorMsg)' != ''"
      Text="Skipping tests in $(AssemblyName) because there is no configuration compatible with the current BuildConfiguration." />
  </Target>

  <Target Name="SetupTestProperties" DependsOnTargets="CheckTestPlatforms;CheckTestCategories" />

  <PropertyGroup>
    <LaunchSettingsOutputFileFullPath>$(MSBuildProjectDirectory)/$(AppDesignerFolder)/launchSettings.json</LaunchSettingsOutputFileFullPath>
    <LaunchSettingsInputFileFullPath>$(MSBuildThisFileDirectory)launchSettings.json</LaunchSettingsInputFileFullPath>
  </PropertyGroup>

  <!--
    Target to generate the launch settings file.
    Conditioned as an opt-in which only runs for invokable test projects.
    Either called by PrepareForRunDependsOn if the file doesn't already exist when building
    the test assembly or invoked manually from the build.proj when doing a full build.
  -->
  <Target Name="GenerateLaunchSettingsFile" Condition="$(IsInvokableTestProject) == 'true' AND '$(GenerateLaunchSettings)' == 'true'">
    <Copy SourceFiles="$(LaunchSettingsInputFileFullPath)"
          DestinationFiles="$(LaunchSettingsOutputFileFullPath)" />
  </Target>

  <PropertyGroup>
    <!--
      Generates the launch settings file at the end of the build in case it doesn't exist yet.
      This supports scenarios when new projects are added or the file was deleted.
    -->
    <PrepareForRunDependsOn Condition="!Exists($(LaunchSettingsOutputFileFullPath))">GenerateLaunchSettingsFile;$(PrepareForRunDependsOn);</PrepareForRunDependsOn>
    <PrepareForRunDependsOn>CopySupplementalTestData;$(PrepareForRunDependsOn);</PrepareForRunDependsOn>
  </PropertyGroup>

  <PropertyGroup>
    <TestDependsOn>
      $(TestDependsOn);
      GenerateTestExecutionScripts;
      RunTestsForProject;
      ArchiveTestBuild
    </TestDependsOn>
  </PropertyGroup>

  <Target Name="Test" DependsOnTargets="$(TestDependsOn)" Condition="'$(SkipTestRun)' != 'true'" />
  <Target Name="BuildAndTest" DependsOnTargets="Build;Test" />
  <Target Name="RebuildAndTest" DependsOnTargets="Rebuild;Test" />

  <!-- This helps collect crash dumps and requires python installed -->
  <Import Project="$(MSBuildThisFileDirectory)Dumpling.targets" Condition="'$(EnableDumpling)' == 'true' OR '$(EnableCloudTest)' == 'true'" />
</Project>