Skip to content

'dotnet test' fails in MTP if file 'Directory.Build.props' sets MSBuild property 'OutputPath' using MSBuild property 'Configuration' #6955

@carl-quintero

Description

@carl-quintero

Describe the bug

When a MTP test project in .NET 10.0.100 (using either Microsoft.NET.Sdk or MSTest.Sdk) uses a file Directory.Build.props that changes the MSBuild property OutputPath to a value that uses the MSBuild property Configuration, dotnet test fails (although with different errors depending on the project sdk):

File Directory.Build.props:

<Project>
   <PropertyGroup>
      <BaseIntermediateOutputPath>$(MSBuildThisFileDirectory)obj\$(Configuration)\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
      <OutputPath>$(MSBuildThisFileDirectory)bin\$(Configuration)\$(MSBuildProjectName)\</OutputPath>
   </PropertyGroup>
</Project>

(Notice the use of the property $(Configuration))

Steps To Reproduce

Repos:

Steps:

  1. Clone the repo(s)

  2. Open a CMD terminal

  3. Change the directory to the directory of the cloned repo

  4. Run:

    dotnet test

Expected behavior

Tests should be found and executed

Actual behavior

  • Case 1 (Microsoft.NET.Sdk):

    You get error:

    Get projects properties with MSBuild didn't execute properly with exit code: 1.

    (In this case at the very least it should be desirable a more helpful error message)

  • Case 2 (MSTest.SDK):

    You get error:

    System.ComponentModel.Win32Exception (2): An error occurred trying to start process '<folder_redacted>\Sample-MSTest.SDK\bin\Test\net10.0\Test.exe' with working directory '<folder_redacted>\Sample-MSTest.SDK'. The system cannot find the file specified.
    

    Notice that the problem is that the output folder bin\Test\net10.0 is used instead of the correct one with the Configuration: bin\Debug\Test\net10.0

Additional context

dotnet test works fine if you delete (or rename) the file Directory.Build.props.

I am aware that I could use dotnet test --test-modules with the compiled binaries (which is what I use in CI/CD pipelines), but for development in the command-line I would like to keep using the dotnet test experience.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: MTPBelongs to the Microsoft.Testing.Platform core libraryExternal: dotnet test`dotnet test` integration

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions