Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable VS Test Explorer without the -vs switch #36126

Merged
merged 2 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ if ($help -or (($null -ne $properties) -and ($properties.Contains('/help') -or $

# VS Test Explorer support for libraries
if ($vs) {
Write-Host "!!! VS Test Explorer now works without the -vs switch. The switch will be removed eventually. !!! "
safern marked this conversation as resolved.
Show resolved Hide resolved
. $PSScriptRoot\common\tools.ps1

# Microsoft.DotNet.CoreSetup.sln is special - hosting tests are currently meant to run on the
Expand Down
14 changes: 13 additions & 1 deletion eng/testing/coverage.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
We need to filter the data to only the assembly being tested. Otherwise we will gather tons of data about other assemblies.
If the code being tested is part of the runtime itself, it requires special treatment.
-->
<PropertyGroup Condition="'$(AssemblyBeingTested)' == ''">
<PropertyGroup Condition="'$(AssemblyBeingTested)' == '' and '$(CreateIntermediateRunSettingsFile)' != 'true'">
<_ProjectDirectoryUnderSourceDir>$(MSBuildProjectDirectory.SubString($(LibrariesProjectRoot.Length)))</_ProjectDirectoryUnderSourceDir>
<AssemblyBeingTested>$(_ProjectDirectoryUnderSourceDir.SubString(0, $(_ProjectDirectoryUnderSourceDir.IndexOfAny("\\/"))))</AssemblyBeingTested>
</PropertyGroup>
Expand Down Expand Up @@ -74,4 +74,16 @@

<Exec Command="$(CoverageReportCommand)" />
</Target>


<!--
Clean the test results directory to guarantee that a report is generated from the
newest coverage results file.
Tracking issue https://github.com/microsoft/vstest/issues/2378.
-->
<Target Name="ClearTestResults"
safern marked this conversation as resolved.
Show resolved Hide resolved
BeforeTargets="VSTest"
Condition="'$(Coverage)' == 'true'">
<RemoveDir Directories="$(OutDir)TestResults" />
</Target>
</Project>
26 changes: 12 additions & 14 deletions eng/testing/runsettings.targets
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<Project>
<PropertyGroup>
<RunSettingsInputFilePath Condition="'$(RunSettingsInputFilePath)' == ''">$(MSBuildThisFileDirectory).runsettings</RunSettingsInputFilePath>
<RunSettingsOutputFilePath Condition="'$(RunSettingsOutputFilePath)' == ''">$(OutDir).runsettings</RunSettingsOutputFilePath>
<RunSettingsInputFilePath>$(MSBuildThisFileDirectory).runsettings</RunSettingsInputFilePath>
<RunSettingsIntermediateOutputFilePath>$(ArtifactsObjDir)$(TargetOS)-$(Configuration)-$(TargetArchitecture).runsettings</RunSettingsIntermediateOutputFilePath>
<RunSettingsAppOutputFilePath>$(OutDir).runsettings</RunSettingsAppOutputFilePath>

<CreateIntermediateRunSettingsFile Condition="'$(CreateIntermediateRunSettingsFile)' == ''">false</CreateIntermediateRunSettingsFile>
<RunSettingsOutputFilePath Condition="'$(CreateIntermediateRunSettingsFile)' == 'true'">$(RunSettingsIntermediateOutputFilePath)</RunSettingsOutputFilePath>
safern marked this conversation as resolved.
Show resolved Hide resolved
<RunSettingsOutputFilePath Condition="'$(CreateIntermediateRunSettingsFile)' != 'true'">$(RunSettingsAppOutputFilePath)</RunSettingsOutputFilePath>

<!-- Set RunSettingsFilePath property which is read by VSTest. -->
<RunSettingsFilePath Condition="Exists('$(RunSettingsOutputFilePath)')">$(RunSettingsOutputFilePath)</RunSettingsFilePath>
<RunSettingsFilePath Condition="Exists('$(RunSettingsAppOutputFilePath)')">$(RunSettingsAppOutputFilePath)</RunSettingsFilePath>
<!-- Use an intermediate runsettings file if the app hasn't been built yet to enable VSTest discovery. -->
<RunSettingsFilePath Condition="'$(RunSettingsFilePath)' == '' and Exists('$(RunSettingsIntermediateOutputFilePath)')">$(RunSettingsIntermediateOutputFilePath)</RunSettingsFilePath>

<PrepareForRunDependsOn>GenerateRunSettingsFile;$(PrepareForRunDependsOn)</PrepareForRunDependsOn>
</PropertyGroup>

Expand Down Expand Up @@ -41,15 +50,4 @@
<RunSettingsFilePath>$(RunSettingsOutputFilePath)</RunSettingsFilePath>
</PropertyGroup>
</Target>

<!--
Clean the test results directory to guarantee that a report is generated from the
newest coverage results file.
Tracking issue https://github.com/microsoft/vstest/issues/2378.
-->
<Target Name="ClearTestResults"
BeforeTargets="VSTest"
Condition="'$(Coverage)' == 'true'">
<RemoveDir Directories="$(OutDir)TestResults" />
</Target>
</Project>
1 change: 0 additions & 1 deletion eng/testing/tests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@
<!-- This app is now can be consumed by xharness CLI to deploy on a device or simulator -->
</Target>

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

<!-- Main test targets -->
Expand Down
1 change: 1 addition & 0 deletions src/libraries/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@

<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
<EnableTestSupport>true</EnableTestSupport>
<EnableRunSettingsSupport>true</EnableRunSettingsSupport>
ViktorHofer marked this conversation as resolved.
Show resolved Hide resolved
<EnableCoverageSupport>true</EnableCoverageSupport>
</PropertyGroup>

Expand Down
5 changes: 3 additions & 2 deletions src/libraries/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,10 @@
<Import Project="$(RepositoryEngineeringDir)codeOptimization.targets" />
<Import Project="$(RepositoryEngineeringDir)references.targets" />
<Import Project="$(RepositoryEngineeringDir)resolveContract.targets" />
<Import Project="$(RepositoryEngineeringDir)testing\runtimeConfiguration.targets" />
<Import Project="$(RepositoryEngineeringDir)testing\tests.targets" Condition="'$(EnableTestSupport)' == 'true'" />
<Import Project="$(RepositoryEngineeringDir)testing\coverage.targets" Condition="'$(EnableCoverageSupport)' == 'true'" />
<Import Project="$(RepositoryEngineeringDir)testing\runtimeConfiguration.targets" />
<Import Project="$(RepositoryEngineeringDir)testing\runsettings.targets" Condition="'$(EnableRunSettingsSupport)' == 'true'" />
<Import Project="$(RepositoryEngineeringDir)testing\coverage.targets" Condition="'$(EnableRunSettingsSupport)' == 'true' or '$(EnableCoverageSupport)' == 'true'" />
safern marked this conversation as resolved.
Show resolved Hide resolved

<Import Sdk="Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk" Project="Sdk.targets" />
<Import Project="$(RepositoryEngineeringDir)restore\repoRestore.targets" Condition="'$(DisableProjectRestore)' == 'true'" />
Expand Down
9 changes: 9 additions & 0 deletions src/libraries/pretest.proj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<PropertyGroup>
<TraversalGlobalProperties>BuildAllProjects=true</TraversalGlobalProperties>
<NETCoreAppFrameworkIdentifier>$(TargetFrameworkIdentifier)</NETCoreAppFrameworkIdentifier>

<!-- Create an intermediate runsettings file to enable VSTest discovery. -->
<EnableRunSettingsSupport>true</EnableRunSettingsSupport>
ViktorHofer marked this conversation as resolved.
Show resolved Hide resolved
<CreateIntermediateRunSettingsFile>true</CreateIntermediateRunSettingsFile>
</PropertyGroup>

<!-- Explicitly build the runtime.depproj project first to correctly set up the testhost. -->
Expand All @@ -19,6 +23,11 @@
Properties="$(TraversalGlobalProperties)" />
</Target>

<Target Name="CreateIntermediateRunSettingsFile"
Condition="'$(ContinuousIntegrationBuild)' != 'true'"
DependsOnTargets="GenerateRunSettingsFile"
BeforeTargets="Build" />

<!-- Microsoft.XmlSerializer.Generator should not be marked as a platform item and be copy-local instead. -->
<Target Name="CollectSharedFrameworkRuntimeFiles"
Condition="'$(PlatformManifestFile)' != '' and '$(BuildingNETCoreAppVertical)' == 'true'">
Expand Down