Skip to content

Commit fd82afe

Browse files
authored
Enable VS Test Explorer without the -vs switch (#36126)
* Enable VS Test Explorer without the -vs switch
1 parent 863d458 commit fd82afe

File tree

7 files changed

+43
-19
lines changed

7 files changed

+43
-19
lines changed

eng/build.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ if ($help -or (($null -ne $properties) -and ($properties.Contains('/help') -or $
6161

6262
# VS Test Explorer support for libraries
6363
if ($vs) {
64+
Write-Host "!!! VS Test Explorer now works without the -vs switch. The switch will be removed eventually. !!! "
6465
. $PSScriptRoot\common\tools.ps1
6566

6667
# Microsoft.DotNet.CoreSetup.sln is special - hosting tests are currently meant to run on the

eng/testing/coverage.targets

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
We need to filter the data to only the assembly being tested. Otherwise we will gather tons of data about other assemblies.
55
If the code being tested is part of the runtime itself, it requires special treatment.
66
-->
7-
<PropertyGroup Condition="'$(AssemblyBeingTested)' == ''">
7+
<PropertyGroup Condition="'$(AssemblyBeingTested)' == '' and '$(CreateIntermediateRunSettingsFile)' != 'true'">
88
<_ProjectDirectoryUnderSourceDir>$(MSBuildProjectDirectory.SubString($(LibrariesProjectRoot.Length)))</_ProjectDirectoryUnderSourceDir>
99
<AssemblyBeingTested>$(_ProjectDirectoryUnderSourceDir.SubString(0, $(_ProjectDirectoryUnderSourceDir.IndexOfAny("\\/"))))</AssemblyBeingTested>
1010
</PropertyGroup>
@@ -74,4 +74,16 @@
7474

7575
<Exec Command="$(CoverageReportCommand)" />
7676
</Target>
77+
78+
79+
<!--
80+
Clean the test results directory to guarantee that a report is generated from the
81+
newest coverage results file.
82+
Tracking issue https://github.com/microsoft/vstest/issues/2378.
83+
-->
84+
<Target Name="ClearTestResults"
85+
BeforeTargets="VSTest"
86+
Condition="'$(Coverage)' == 'true'">
87+
<RemoveDir Directories="$(OutDir)TestResults" />
88+
</Target>
7789
</Project>

eng/testing/runsettings.targets

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
<Project>
22
<PropertyGroup>
3-
<RunSettingsInputFilePath Condition="'$(RunSettingsInputFilePath)' == ''">$(MSBuildThisFileDirectory).runsettings</RunSettingsInputFilePath>
4-
<RunSettingsOutputFilePath Condition="'$(RunSettingsOutputFilePath)' == ''">$(OutDir).runsettings</RunSettingsOutputFilePath>
3+
<RunSettingsInputFilePath>$(MSBuildThisFileDirectory).runsettings</RunSettingsInputFilePath>
4+
<RunSettingsIntermediateOutputFilePath>$(ArtifactsObjDir)$(TargetOS)-$(Configuration)-$(TargetArchitecture).runsettings</RunSettingsIntermediateOutputFilePath>
5+
<RunSettingsAppOutputFilePath>$(OutDir).runsettings</RunSettingsAppOutputFilePath>
6+
7+
<CreateIntermediateRunSettingsFile Condition="'$(CreateIntermediateRunSettingsFile)' == ''">false</CreateIntermediateRunSettingsFile>
8+
<RunSettingsOutputFilePath Condition="'$(CreateIntermediateRunSettingsFile)' == 'true'">$(RunSettingsIntermediateOutputFilePath)</RunSettingsOutputFilePath>
9+
<RunSettingsOutputFilePath Condition="'$(CreateIntermediateRunSettingsFile)' != 'true'">$(RunSettingsAppOutputFilePath)</RunSettingsOutputFilePath>
10+
511
<!-- Set RunSettingsFilePath property which is read by VSTest. -->
6-
<RunSettingsFilePath Condition="Exists('$(RunSettingsOutputFilePath)')">$(RunSettingsOutputFilePath)</RunSettingsFilePath>
12+
<RunSettingsFilePath Condition="Exists('$(RunSettingsAppOutputFilePath)')">$(RunSettingsAppOutputFilePath)</RunSettingsFilePath>
13+
<!-- Use an intermediate runsettings file if the app hasn't been built yet to enable VSTest discovery. -->
14+
<RunSettingsFilePath Condition="'$(RunSettingsFilePath)' == '' and Exists('$(RunSettingsIntermediateOutputFilePath)')">$(RunSettingsIntermediateOutputFilePath)</RunSettingsFilePath>
15+
716
<PrepareForRunDependsOn>GenerateRunSettingsFile;$(PrepareForRunDependsOn)</PrepareForRunDependsOn>
817
</PropertyGroup>
918

@@ -41,15 +50,4 @@
4150
<RunSettingsFilePath>$(RunSettingsOutputFilePath)</RunSettingsFilePath>
4251
</PropertyGroup>
4352
</Target>
44-
45-
<!--
46-
Clean the test results directory to guarantee that a report is generated from the
47-
newest coverage results file.
48-
Tracking issue https://github.com/microsoft/vstest/issues/2378.
49-
-->
50-
<Target Name="ClearTestResults"
51-
BeforeTargets="VSTest"
52-
Condition="'$(Coverage)' == 'true'">
53-
<RemoveDir Directories="$(OutDir)TestResults" />
54-
</Target>
5553
</Project>

eng/testing/tests.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@
217217
<!-- This app is now can be consumed by xharness CLI to deploy on a device or simulator -->
218218
</Target>
219219

220-
<Import Project="$(MSBuildThisFileDirectory)runsettings.targets" />
221220
<Import Project="$(MSBuildThisFileDirectory)xunit\xunit.targets" Condition="'$(TestFramework)' == 'xunit'" />
222221

223222
<!-- Main test targets -->

src/libraries/Directory.Build.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,9 @@
327327

328328
<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
329329
<EnableTestSupport>true</EnableTestSupport>
330-
<EnableCoverageSupport>true</EnableCoverageSupport>
330+
<!-- TODO: Remove these conditions when VSTest is used in CI. -->
331+
<EnableRunSettingsSupport Condition="'$(ContinuousIntegrationBuild)' != 'true'">true</EnableRunSettingsSupport>
332+
<EnableCoverageSupport Condition="'$(ContinuousIntegrationBuild)' != 'true'">true</EnableCoverageSupport>
331333
</PropertyGroup>
332334

333335
<Import Project="$(RepositoryEngineeringDir)testing\tests.props" Condition="'$(EnableTestSupport)' == 'true'" />

src/libraries/Directory.Build.targets

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,10 @@
136136
<Import Project="$(RepositoryEngineeringDir)codeOptimization.targets" />
137137
<Import Project="$(RepositoryEngineeringDir)references.targets" />
138138
<Import Project="$(RepositoryEngineeringDir)resolveContract.targets" />
139-
<Import Project="$(RepositoryEngineeringDir)testing\runtimeConfiguration.targets" />
140139
<Import Project="$(RepositoryEngineeringDir)testing\tests.targets" Condition="'$(EnableTestSupport)' == 'true'" />
141-
<Import Project="$(RepositoryEngineeringDir)testing\coverage.targets" Condition="'$(EnableCoverageSupport)' == 'true'" />
140+
<Import Project="$(RepositoryEngineeringDir)testing\runtimeConfiguration.targets" />
141+
<Import Project="$(RepositoryEngineeringDir)testing\runsettings.targets" Condition="'$(EnableRunSettingsSupport)' == 'true'" />
142+
<Import Project="$(RepositoryEngineeringDir)testing\coverage.targets" Condition="'$(EnableRunSettingsSupport)' == 'true' or '$(EnableCoverageSupport)' == 'true'" />
142143

143144
<Import Sdk="Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk" Project="Sdk.targets" />
144145
<Import Project="$(RepositoryEngineeringDir)restore\repoRestore.targets" Condition="'$(DisableProjectRestore)' == 'true'" />

src/libraries/pretest.proj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
<NETCoreAppFrameworkIdentifier>$(TargetFrameworkIdentifier)</NETCoreAppFrameworkIdentifier>
77
</PropertyGroup>
88

9+
<PropertyGroup Condition="'$(ContinuousIntegrationBuild)' != 'true'">
10+
<!-- Create an intermediate runsettings file to enable VSTest discovery. -->
11+
<EnableRunSettingsSupport>true</EnableRunSettingsSupport>
12+
<CreateIntermediateRunSettingsFile>true</CreateIntermediateRunSettingsFile>
13+
</PropertyGroup>
14+
915
<!-- Explicitly build the runtime.depproj project first to correctly set up the testhost. -->
1016
<ItemGroup>
1117
<RuntimeProject Include="restore\runtime\runtime.depproj" />
@@ -19,6 +25,11 @@
1925
Properties="$(TraversalGlobalProperties)" />
2026
</Target>
2127

28+
<Target Name="CreateIntermediateRunSettingsFile"
29+
Condition="'$(CreateIntermediateRunSettingsFile)' == 'true'"
30+
DependsOnTargets="GenerateRunSettingsFile"
31+
BeforeTargets="Build" />
32+
2233
<!-- Microsoft.XmlSerializer.Generator should not be marked as a platform item and be copy-local instead. -->
2334
<Target Name="CollectSharedFrameworkRuntimeFiles"
2435
Condition="'$(PlatformManifestFile)' != '' and '$(BuildingNETCoreAppVertical)' == 'true'">

0 commit comments

Comments
 (0)