Buildalyzer icon indicating copy to clipboard operation
Buildalyzer copied to clipboard

method AnalyzerResultExtension.AddToWorkspace doesn't check for duplicate projects in solution

Open ltcmelo opened this issue 4 years ago • 4 comments

Consider the following snippet.

analyzerResult = projAnalyzer.Build();
…
analyzerResult.AddToWorkspace(workspace, true);

Now, assume that the project to which the object projAnalyzer is associated with has structure such as that of this project — from a Roslyn issue.

Then, the addition to the workspace triggers an InvalidOperationException. I imagine that Buildalyzer should check the presence of the project before adding it (due to transitive references).

ltcmelo avatar Dec 02 '20 17:12 ltcmelo

I'm having a little trouble understanding the issue here. Can you provide any more details about the InvalidOperationException generated in this case? Is it coming from Buildalyzer directly (and if so, where?) or from Roslyn?

What would really help is a reproducible Solution and Project file(s) so I can see exactly what's going on.

daveaglick avatar Dec 20 '20 19:12 daveaglick

The InvalidOperationException is generated from MSBuild API, but it does so because Buildalyzer adds duplicate Projects to a Solution/Workspace.

You can reproduce this issue by creating .csproj files that map the organization I mentioned here, requesting their corresponding ProjectAnalyzers to build and passing true as the option to (automatically) include project references.

ltcmelo avatar Dec 20 '20 20:12 ltcmelo

I just did some related work on transitive references in Roslyn workspaces in #181 which should hopefully help with the scenario here, but I still can't reproduce anything like the InvalidOperationException you describe. Any chance you could work up a small reproducible project with the latest version that exhibits this problem? This might be a good starting point: https://github.com/slang25/BuildalyzerBugRepro

daveaglick avatar Aug 17 '21 01:08 daveaglick

Any chance you could work up a small reproducible project with the latest version that exhibits this problem?

@daveaglick the project I describe here reproduces the issue I mention.

ltcmelo avatar Aug 17 '21 11:08 ltcmelo