Closed jliglesias66 closed 5 years ago
The .NET assembly loader tries to load all types referenced within a method before loading the method, so before it starts running your Main
method, it tries to locate MSBuild assemblies. Since the Locator isn't set up until the first line inside the method, that fails.
This is mentioned in the doc page you linked,
Add a call to the Locator API before calling any method that uses MSBuild.
but it's a pretty subtle behavior. If you have any ideas about how to call it out more clearly in the documentation, we'd love to hear them.
Closing, in the hopes that helped.
@rainersigwald wow, that is some devilishly tricky behavior. I spent quite a while trying to figure out why my code wasn't working. I like your idea of an analyzer, but in the meantime would it make sense for a correct vs. incorrect code example to appear on the referenced documentation page?
Steps to reproduce
Following the steps in this article https://docs.microsoft.com/en-us/visualstudio/msbuild/updating-an-existing-application?view=vs-2019
Add next code
.csproj file
The project compiles fine but in runtime it shows the following message: "The application is in break mode" exception "Could not load file or assembly Microsoft.Build, Version=15.1.0.0"... What am I doing wrong?