phmonte / Buildalyzer

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

Buildalyzer could not load files or assemblies #206

Closed Liam-Rougoor closed 5 months ago

Liam-Rougoor commented 2 years ago

I'm using Buildalyzer to load projects in a given solution to perform some analysis on the projects' documents. I'm trying to test my implementation on its own solution, but it's showing some weird behaviours:

When I build the project in Visual Studio 2022, everything works fine. I'm stuck on where this problem is coming from and how to proceed. Is this expected behaviour, or some bug? Is there something I'm missing that I need to fix?

Liam-Rougoor commented 2 years ago

An update: I copied the solution and the faulty project to a new solution. When I run my implementation on the copy, it all works. So I assume the exception has to do with the project trying to build itself again at runtime. Is this intended, or is there still a workaround to this?

daveaglick commented 2 years ago

So I assume the exception has to do with the project trying to build itself again at runtime. Is this intended, or is there still a workaround to this?

By default Buildalyzer calls MSBuild (or dotnet build depending on .NET Core vs. Framework, which indirectly calls MSBuild anyway). It tried to do this as closely to a "normal" build as possible - over the years I've discovered that the more Buildalyzer deviates from that, the more problems arise. However, this does create a separate class of problem as you've noticed because it'll shell out to MSBuild, which then tries to build in the normal place. If you're running the application from there at the same time I'd expect some oddness like locked files, etc.

The trick is probably to change the output path, intermediate path, etc. for your particular use case. For more context and some examples see https://github.com/daveaglick/Buildalyzer/issues/105 - let me know if that helps at all.

daveaglick commented 2 years ago

Just checking in - have you had any luck with the suggestions above?

rouke-broersma commented 1 year ago

@Liam-Rougoor ?

phmonte commented 5 months ago

I close this issue, I believe that one of the suggestions resolved it. Feel free to reopen it with an update.