Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build/assembly reference not found errors due to random sorting of the projects in the Workspace when loading projects from solution file #241

Closed
hideintheclouds opened this issue Dec 11, 2023 · 9 comments
Labels
⚠ Bug Something isn't working as expected Feedback Needed Further information is requested

Comments

@hideintheclouds
Copy link

hideintheclouds commented Dec 11, 2023

There seems to be a problem in the way the projects from a solution are loaded into the workspace.

When part of a solution, the projects might have dependencies and they will require a certain build order.
When getting the Workspace, it seems that the workspace is randomly building them.

      this.Workspace = Manager.GetWorkspace();

As a result of this behaviour, there are assembly reference errors that appear in some of the projects' compilation as severity=error diagnostics.

Please have a look at the following bug for a detailed explanation and for some possible workarounds, including a method to returned a sorted Workspace (GetOrderedWorkspace)

@daveaglick
Copy link
Collaborator

Please have a look at the following bug

Was there supposed to be a log file or bug linked here? If so, I don't see it.

Is the problem here that the build itself isn't correctly ordered? We just "shell out" to MSBuild or dotnet build so any project ordering based on the reference graph is the responsibility of MSBuild.

Or am I misunderstanding the problem? Is it that projects are being added into the Roslyn Workspace in an order where some are relying on references from others that haven't been added yet? If this is the case, how could we determine the "correct" order?

Perhaps most importantly is whether there's a reproduceable example of this problem. It'll be hard for me to diagnose and verify a fix without one.

@daveaglick daveaglick added the Feedback Needed Further information is requested label Dec 19, 2023
@hideintheclouds
Copy link
Author

Hi Dave,
I updated the initial text with the proper url.
I suspect the problem is somehow similar to the second option that you mentioned.

I encountered the issue on a private solution with multiple csproj files, and unfortunately cannot share the source code.

I think that the issue was reported initially using the eShopOnContainers solution as specified in the referenced url.

@daveaglick
Copy link
Collaborator

I think I'm starting to understand the issue after reading the link. I'll implement the fix identified in that thread and see if it helps.

daveaglick added a commit that referenced this issue Dec 20, 2023
…spaces to be based on the Solution order, if there is a Solution (#241, eNeRGy164/LivingDocumentation#56)
@daveaglick daveaglick added ⚠ Bug Something isn't working as expected and removed Feedback Needed Further information is requested labels Dec 20, 2023
@daveaglick
Copy link
Collaborator

Buildalyzer 6.0.2 is rolling out to NuGet now. Can you test it when you get the chance (you might need to reference the latest version explicitly in your project if you're getting it transitively through LivingDocumentation)?

@daveaglick daveaglick added the Feedback Needed Further information is requested label Dec 20, 2023
@hideintheclouds
Copy link
Author

Trying the 6.0.2 did not fix the issue. Now the projects always come in the same order in the AdhocWorkspace, but it seems not to find namespaces in the build dependencies (as before).
Note: I was however able to have a working solution using the extension method that @AndreasKim created.

I believe the difference is made by the following:

foreach (AnalyzerResult result in results)
            {
                if (!workspace.CurrentSolution.Projects.Any(p => p.FilePath == result.ProjectFilePath))
                {
                    result.AddToWorkspace(workspace, true);
                }
            }

            return workspace;

When calling the AddToWorkspace with addProjectReferences=true, it seems to add results to the workspace, but also rebuilding and adding the referenced projects.
I even commented out the sorting of the projects, and it still works when calling result.AddToWorkspace(workspace, true);

@daveaglick
Copy link
Collaborator

Of course that's the one little bit I accidentally left out :). I added that flag and 6.0.3 is rolling out now. Hopefully that resolves it once and for all, do you mind checking one more time?

@hideintheclouds
Copy link
Author

6.0.3 tag seems to point to the same commit as 6.0.2:
https://github.com/daveaglick/Buildalyzer/releases

I imagine that 6.0.3 should be associated with a new commit corresponding to the change?

@daveaglick
Copy link
Collaborator

Whops! I got carried away and published the release before committing the code. I publish locally so the 6.0.3 up on NuGet actually does have the change, I just need to update the tag.

@hideintheclouds
Copy link
Author

Thanks, it seems to be working fine with 6.0.3, I guess that parameter made a difference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚠ Bug Something isn't working as expected Feedback Needed Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants