dotnet / dotnet/project-system

Duplicate ProjectReferences with different paths to same project are not deduplicated

Open
#7,952 0 comments 0 reactions 0 assignees View on GitHub
Triage-Investigate
Dominant language
C#
Stars
1k
Forks
415
PR merge metrics
No merged PRs in 30d

Description

## Visual Studio Version

both dev16 and dev17

## Summary

This all started following an internal customer reporting a problem using NuGet with lock files. Their org mandates a large and complex SDK/build system. Therefore, their repo is so incredibly complex, and I can't reproduce the same error, but I got something close. For reasons I couldn't figure out, some of their projects are getting two references to the same project, one with relative path, one with absolute path.

## Steps to Reproduce

Have a solution with two projects, one of which has two project references to the other project, once using absolute path (for example using `$(MSBuildThisFileDirectory)..\other\project.csproj`) and another using absolute path.

## Expected Behavior

MSBuild deduplicates the project references, the same as when two project references are using the exact same syntax

## Actual Behavior

using `$env:CPS_DiagnosticRuntime = 1` I see:

```
Project References
C:\src\test\multiplePRojectRefs\Lib1\Lib1.csproj -- (TreatAsUsed: | ProjectFileFullPath:C:\src\test\multiplePRojectRefs\Lib1\Lib1.csproj | Project: | CopyLocalSatelliteAssemblies: | DefiningProjectFullPath:C:\src\test\multiplePRojectRefs\Directory.Build.props | Description: | CopyLocal: | UseLibraryDependencyInputs: | ReferenceOutputAssembly: | DefiningProjectDirectory:C:\src\test\multiplePRojectRefs\ | ReferencedProjectIdentifier: | ResolvedPath:C:\src\test\multiplePRojectRefs\Lib1\Lib1.csproj | Version: | EmbedInteropTypes: | Visible: | LinkLibraryDependencies: | Identity:C:\src\test\multiplePRojectRefs\Lib1\Lib1.csproj | Culture: | IncludeAssets: | BrowsePath:C:\src\test\multiplePRojectRefs\Lib1\Lib1.csproj | PrivateAssets: | ExcludeAssets: | IsImplicitlyDefined: | Aliases:)
..\Lib1\Lib1.csproj -- (TreatAsUsed: | ProjectFileFullPath:C:\src\test\multiplePRojectRefs\Lib1\Lib1.csproj | Project: | CopyLocalSatelliteAssemblies: | DefiningProjectFullPath:C:\src\test\multiplePRojectRefs\MyApp\MyApp.csproj | Description: | CopyLocal: | UseLibraryDependencyInputs: | ReferenceOutputAssembly: | DefiningProjectDirectory:C:\src\test\multiplePRojectRefs\MyApp\ | ReferencedProjectIdentifier: | ResolvedPath:..\Lib1\Lib1.csproj | Version: | EmbedInteropTypes: | Visible: | LinkLibraryDependencies: | Identity:..\Lib1\Lib1.csproj | Culture: | IncludeAssets: | BrowsePath:..\Lib1\Lib1.csproj | PrivateAssets: | ExcludeAssets: | IsImplicitlyDefined: | Aliases:)
```

Also in Solution explorer:
![image](https://user-images.githubusercontent.com/5030577/156845229-15a5fba5-4d03-441d-a33b-2317977609cf.png)

## User Impact

This customer (and their whole team) are almost unable to use VS at all.

I'm fixing it from NuGet's side with https://github.com/NuGet/NuGet.Client/pull/4477, but I want to raise awareness with you here. As previously mentioned, my repro is not causing NuGet to fail locked mode restore, I don't know why, but the CPS nomination and solution explorer issues are visible ways to see the double project reference issue.

[multiplePRojectRefs.zip](https://github.com/dotnet/project-system/files/8188896/multiplePRojectRefs.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.