[Bug]: Build with references fails if absolute path contains a symlink
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
### Issue Description
A project containing references will fail to build/find reference assemblies if built using relative paths first.
### Steps to Reproduce
Attached minimal sample [dotnet-project.zip](https://github.com/dotnet/msbuild/files/13998267/dotnet-project.zip) contains two projects -- `main` referencing `lib`. The error is reproducible whenever path to filesystem root contains a symlink:
```
#!/bin/sh
cd ~ && mkdir my-projects && cd my-projects
# either
# unzip ~/dotnet-project.zip
# or
mkdir dotnet-project && cd dotnet-project
dotnet new console -o main
dotnet new classlib -o lib
dotnet add main reference lib
cd ~ && ln -s my-projects/dotnet-project . && cd dotnet-project
dotnet build main/main.csproj
dotnet build `pwd`/main/main.csproj
```
### Expected Behavior
Second invocation of `dotnet build` should succeed.
### Actual Behavior
Second build above fails with following message:
```
CSC : error CS0006: Metadata file '/home/user/dotnet-project/lib/obj/Debug/net6.0/ref/lib.dll' could not be found [/home/user/dotnet-project/main/main.csproj]
```
Second invocation will succeed though.
While inconvenient in general this also breaks C# tooling in VS Code (I cannot compile/run/debug tests whenever a path to a project contains a symlink).
### Analysis
For what it's worth, with the failed build above, the `lib/obj/Debug/net6.0/ref/lib.dll` is the only one not being created -- both `lib/obj/Debug/net6.0/refint/lib.dll` `lib/bin/Debug/net6.0/lib.dll` are still being built successfully.
### Versions & Configurations
```
$ DOTNET_CLI_UI_LANGUAGE=en dotnet msbuild -version
MSBuild version 17.8.3+195e7f5a3 for .NET
17.8.3.51904%
$ echo $SHELL
/bin/zsh
$ /bin/zsh --version
zsh 5.9 (x86_64-unknown-linux-gnu)
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.