phmonte / Buildalyzer

A utility to perform design-time builds of .NET projects without having to think too hard about it.
MIT License
593 stars 94 forks source link

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

Open ltcmelo opened 3 years ago

ltcmelo commented 3 years ago

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).

daveaglick commented 3 years ago

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.

ltcmelo commented 3 years ago

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.

daveaglick commented 2 years ago

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

ltcmelo commented 2 years ago

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.