Skip to content

IntermediateOutputPath absolute path causes exe to be overwritten #11110

@timcassell

Description

@timcassell

Issue Description

Discovered in dotnet/BenchmarkDotNet#2664, passing /p:IntermediateOutputPath= with an absolute path causes the exe of a referenced project to be overwritten by the project referencing it.

Steps to Reproduce

  1. Create a C# console app project
Console.WriteLine("Hello World from ConsoleApp1");
  1. Create a second C# console app project
Console.WriteLine("Hello World from ConsoleApp2");
  1. Add a project reference to the second project from the first project
<ItemGroup>
  <ProjectReference Include="..\ConsoleApp2\ConsoleApp2.csproj" />
</ItemGroup>
  1. Build the project with dotnet sdk, passing absolute output paths.
dotnet build -c Release /p:IntermediateOutputPath=C:\Users\Tim\source\repos\BuildPathBug\obj/
  1. Run the produced ConsoleApp2.exe in the bin directory of ConsoleApp1.

Additional notes:

If I also include /p:OutDir= so that both projects output to the same bin directory, the ConsoleApp2.exe is correct if I do not include /p:IntermediateOutputPath=, and incorrect if I do include it.
Likewise, with both /p:IntermediateOutputPath= and /p:OutDir= included, the ConsoleApp2.exe is correct if I do not include the project reference in step 3, and incorrect if it is included.

Expected Behavior

Console prints Hello World from ConsoleApp2.

Actual Behavior

Console prints Hello World from ConsoleApp1.

Analysis

No response

Versions & Configurations

msbuild -version

Microsoft (R) Build Engine version 16.6.0 for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

16.6.0.22901

dotnet --version

9.0.101

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: DocumentationIssues about docs, including errors and areas we should extend (this repo and learn.microsoft.com)Priority:2Work that is important, but not critical for the releasetriaged

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions