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

IntermediateOutputPath absolute path causes exe to be overwritten #11110

Open
timcassell opened this issue Dec 8, 2024 · 2 comments
Open

IntermediateOutputPath absolute path causes exe to be overwritten #11110

timcassell opened this issue Dec 8, 2024 · 2 comments
Labels
Documentation Issues about docs, including errors and areas we should extend (this repo and learn.microsoft.com) Priority:2 Work that is important, but not critical for the release triaged

Comments

@timcassell
Copy link

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
@maridematte maridematte added Documentation Issues about docs, including errors and areas we should extend (this repo and learn.microsoft.com) Priority:2 Work that is important, but not critical for the release triaged labels Dec 10, 2024
@maridematte
Copy link
Contributor

This seems to be expected behaviour within MSBuild, anything on intermediate output path will be rewritten during the build. To avoid that you can pass a relative path depending on the built project instead.

We do need to write better docs about this case. Probably within the project properties learn page.

@baronfel
Copy link
Member

That's my take as well @maridematte - setting core/internal properties that by design will vary per-project directly on the command line is fraught with errors, I would never suggest setting any of the output directory-influencing properties directly in this way as a result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues about docs, including errors and areas we should extend (this repo and learn.microsoft.com) Priority:2 Work that is important, but not critical for the release triaged
Projects
None yet
Development

No branches or pull requests

3 participants