You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's a very common problem using Locator, which is that the natural code change to use it:
void DoStuff()
{
+ MSBuildLocator.RegisterDefaults();
var project = new Microsoft.Build.Evaluation.Project(projectPath);
Doesn't work, because .NET loads all types referenced in a method before executing that method, so it tries to load MSBuild APIs before the Locator has made that possible.
#64 is one example of this but there have been a ton.
We can't fix this in the deployed code, because it won't have been loaded in time to do anything.
It might be possible, though, to create a Roslyn analyzer that ships as part of this package that checks to make sure there are no MSBuild APIs in a method that calls the locator. That would make things much easier for new users.
The text was updated successfully, but these errors were encountered:
Why not do it in a static constructor from a type that does not reference any other type? Excluding the usual caveats with exceptions from type constructors.
There's a very common problem using Locator, which is that the natural code change to use it:
void DoStuff() { + MSBuildLocator.RegisterDefaults(); var project = new Microsoft.Build.Evaluation.Project(projectPath);
Doesn't work, because .NET loads all types referenced in a method before executing that method, so it tries to load MSBuild APIs before the Locator has made that possible.
#64 is one example of this but there have been a ton.
We can't fix this in the deployed code, because it won't have been loaded in time to do anything.
It might be possible, though, to create a Roslyn analyzer that ships as part of this package that checks to make sure there are no MSBuild APIs in a method that calls the locator. That would make things much easier for new users.
The text was updated successfully, but these errors were encountered: