Skip to content

Allow customise test log output location #12485

@RussKie

Description

@RussKie
  • This issue is blocking
  • This issue is causing unreasonable pain

The solution I'm currently working consists of hundreds of projects (many of which a test projects). As a result the ./artifacts/logs folder gets filled with many *.log files (example). It makes it difficult to see other logs produced during the build.
The paths are configured here:

<Target Name="_InnerGetTestsToRun"
Outputs="%(_TestArchitectureItems.Identity)"
Returns="@(TestToRun)"
Condition="'$(TestRuntime)' != '' and '$(SkipTests)' != 'true' and
('$(TestTargetFrameworks)' == '' or $([System.String]::new(';$(TestTargetFrameworks);').Contains(';$(TargetFramework);')))">
<PropertyGroup>
<_TestArchitecture>%(_TestArchitectureItems.Identity)</_TestArchitecture>
<_ResultFileNameNoExt>$(MSBuildProjectName)_$(TargetFramework)_$(_TestArchitecture)</_ResultFileNameNoExt>
</PropertyGroup>
<ItemGroup>
<TestToRun Include="$(TargetPath)">
<TargetFramework>$(TargetFramework)</TargetFramework>
<TargetFrameworkIdentifier>$(TargetFrameworkIdentifier)</TargetFrameworkIdentifier>
<TargetFrameworkVersion>$(TargetFrameworkVersion)</TargetFrameworkVersion>
<TestRuntime>$(TestRuntime)</TestRuntime>
<TestTimeout>$(TestTimeout)</TestTimeout>
<Architecture>$(_TestArchitecture)</Architecture>
<EnvironmentDisplay>$(TargetFramework)|$(_TestArchitecture)</EnvironmentDisplay>
<ResultsFilePathWithoutExtension>$(_ResultFileNameNoExt)</ResultsFilePathWithoutExtension>
<ResultsXmlPath>$(ArtifactsTestResultsDir)$(_ResultFileNameNoExt).xml</ResultsXmlPath>
<ResultsTrxPath>$(ArtifactsTestResultsDir)$(_ResultFileNameNoExt).trx</ResultsTrxPath>
<ResultsHtmlPath>$(ArtifactsTestResultsDir)$(_ResultFileNameNoExt).html</ResultsHtmlPath>
<ResultsStdOutPath>$(ArtifactsLogDir)$(_ResultFileNameNoExt).log</ResultsStdOutPath>
<TestRunnerAdditionalArguments>$(TestRunnerAdditionalArguments)</TestRunnerAdditionalArguments>
</TestToRun>
</ItemGroup>
</Target>

I'm specifically interested in ResultsStdOutPath, and it doesn't look like the destination path can be easily customised (short of changing ArtifactsLogDir variable).

May we entertain the following tweak?

    <PropertyGroup>
      <_TestArchitecture>%(_TestArchitectureItems.Identity)</_TestArchitecture>
      <_ResultFileNameNoExt>$(MSBuildProjectName)_$(TargetFramework)_$(_TestArchitecture)</_ResultFileNameNoExt>

+     <TestResultsLogDir Condition=" '$(TestResultsLogDir)' == '' ">$(ArtifactsLogDir)</TestResultsLogDir>
    </PropertyGroup>

    <ItemGroup>
      <TestToRun Include="$(TargetPath)">
        <TargetFramework>$(TargetFramework)</TargetFramework>
        <TargetFrameworkIdentifier>$(TargetFrameworkIdentifier)</TargetFrameworkIdentifier>
        <TargetFrameworkVersion>$(TargetFrameworkVersion)</TargetFrameworkVersion>
        <TestRuntime>$(TestRuntime)</TestRuntime>
        <TestTimeout>$(TestTimeout)</TestTimeout>
        <Architecture>$(_TestArchitecture)</Architecture>
        <EnvironmentDisplay>$(TargetFramework)|$(_TestArchitecture)</EnvironmentDisplay>
        <ResultsFilePathWithoutExtension>$(_ResultFileNameNoExt)</ResultsFilePathWithoutExtension>
        <ResultsXmlPath>$(ArtifactsTestResultsDir)$(_ResultFileNameNoExt).xml</ResultsXmlPath>
        <ResultsTrxPath>$(ArtifactsTestResultsDir)$(_ResultFileNameNoExt).trx</ResultsTrxPath>
        <ResultsHtmlPath>$(ArtifactsTestResultsDir)$(_ResultFileNameNoExt).html</ResultsHtmlPath>
-       <ResultsStdOutPath>$(ArtifactsLogDir)$(_ResultFileNameNoExt).log</ResultsStdOutPath>
+       <ResultsStdOutPath>$(TestResultsLogDir)$(_ResultFileNameNoExt).log</ResultsStdOutPath>
        <TestRunnerAdditionalArguments>$(TestRunnerAdditionalArguments)</TestRunnerAdditionalArguments>
      </TestToRun>
    </ItemGroup>
  </Target>

This way I can alter my solution's config as this:

  <PropertyGroup>
    <TestResultsLogDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsLogDir)', 'TestLogs'))</TestResultsLogDir>
  </PropertyGroup>

...and have tests in a subfolder:
image

Release Note Category

  • Feature changes/additions
  • Bug fixes
  • Internal Infrastructure Improvements

Release Note Description

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions