Duplicated project when reading sln when multiple TargetPlatforms are specified #56806
Open
Description
Version Used:
<PackageReference Include="Microsoft.Build" Version="16.11.0" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.4.1" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="16.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="3.11.0" />
Running on linux:
Linux 5.11.0-36-generic #40~20.04.1-Ubuntu SMP Sat Sep 18 02:14:19 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Steps to Reproduce:
- Cloned the repo https://github.com/structurizr/dotnet/tree/29f94266dfb0c4d876221e837c2f0443cc86bef6
- Run the following code for the
Structurizr.sln
present at the root of the repo:
MSBuildLocator.RegisterDefaults();
var workspace = MSBuildWorkspace.Create();
var solutionFile = await workspace.OpenSolutionAsync(solutionPath);
var projectsList = solutionFile.Projects.ToList();
- Also run the following (after step 2):
var dependencySets = solutionFile.GetProjectDependencyGraph().GetDependencySets().ToList()
Expected Behavior:
- I should have received 5 projects in
projectsList
in step 2:
[0]: {Structurizr.Core(netstandard2.0, net45)}
[1]: {Structurizr.Core.Tests}
[2]: {Structurizr.Examples}
[3]: {Structurizr.Client(netstandard2.0, net45)}
[4]: {Structurizr.Client.Tests}
Actual Behavior:
- Instead I received 7 projects
projectsList
in total in step 2:
[0]: {Structurizr.Core(netstandard2.0)}
[1]: {Structurizr.Core(net45)}
[2]: {Structurizr.Core.Tests}
[3]: {Structurizr.Examples}
[4]: {Structurizr.Client(netstandard2.0)}
[5]: {Structurizr.Client(net45)}
[6]: {Structurizr.Client.Tests}
Note that index 0,1 and 4,5 simply have two target platforms.
Secondly upon running step 3, I received 2 dependency sets:
A.
dependencySets[0].ToList()
{Count = 6}
[0]: {(ProjectId, #084645c9-2741-4b23-9d6d-009a989db8dc - /tmp/code/structurizr-dotnet/Structurizr.Core/Structurizr.Core.csproj)}
[1]: {(ProjectId, #f169e5f6-3ef2-4311-b585-444ab8ed4e7c - /tmp/code/structurizr-dotnet/Structurizr.Core.Tests/Structurizr.Core.Tests.csproj)}
[2]: {(ProjectId, #dca51dae-5f2a-4c65-a564-84a106fadf3c - /tmp/code/structurizr-dotnet/Structurizr.Client/Structurizr.Client.csproj)}
[3]: {(ProjectId, #b6a44263-558d-4968-aeaa-a2c2b188a153 - /tmp/code/structurizr-dotnet/Structurizr.Client/Structurizr.Client.csproj)}
[4]: {(ProjectId, #8bf0e88d-e7d5-49f3-88e2-be60c1425769 - /tmp/code/structurizr-dotnet/Structurizr.Client.Tests/Structurizr.Client.Tests.csproj)}
[5]: {(ProjectId, #a6bdf8b0-41d5-4ada-840c-fc08c4b0b73c - /tmp/code/structurizr-dotnet/Structurizr.Examples/Structurizr.Examples.csproj)}
B.
dependencySets[1].ToList()
{Count = 1}
[0]: {(ProjectId, #97b4a23e-00e5-4c51-9e45-4ea882bb16e3 - /tmp/code/structurizr-dotnet/Structurizr.Core/Structurizr.Core.csproj)}
Q1. Why am I receiving 7 projects instead of 5 in step 2, just by targetting 2 platforms and why is the split 5 and 2.
Q2. Another issue is, doing the same under Windows (VS Version 17.0.0 Preview 4.0) I get 5 and 2 dependency sets instead, index 2 or 3 from A moves to B. Why this different behavior across different OS?